목록Collections (1)
Stack Building
collections 모듈
컨테이너에 동일한 값의 자료가 몇 개인지 파악하는 데에 사용. 가장 수가 큰 것부터 출력한다. 1. 리스트 import collections list = ['a', 'b', 'b', 'c'] print(collections.Counter(list)) >>Counter({'b':2, 'a':1, 'c':1}) 2. 딕셔너리 import collections print(collections.Counter({'가': 3, '나': 2, '다': 4})) >>Counter({'다': 4, '가': 3, '나': 2}) 3. 값=개수 import collections c = collections.Counter(a=2, b=3, c=2) print(collections.Counter(c)) print(sorted(..
Python
2019. 7. 13. 23:22