from collections import Counter
letters = 'aabbbcadd'
c = Counter(letters)
print(c)
# Counter({'a': 3, 'b': 3, 'd': 2, 'c': 1})
정말 Counter 를 사용하게 되면 간편하게 string 안에
from collections import Counter
counter1 = Counter('aabbccddeaaccdf').most_common() # 인자를 주지않으면 전체요소 출력
counter2 = Counter('aabbccddeaaccdf').most_common(1) # 상위요소 하나 출력
counter3 = Counter('aabbccddeaaccdf').most_common(2) # 상위요소 두개 출력
print(counter1) # [('a', 4), ('c', 4), ('d', 3), ('b', 2), ('e', 1), ('f', 1)]
print(counter2) # [('a', 4)]
print(counter3) # [('a', 4), ('c', 4)]
most_common()
from collections import Counter
counter1 = Counter(['jakdu' , 'sory' , 'kim' , 'ahn'])
counter2 = Counter(['jakdu' , 'kim' , 'ahn'])
print(counter1) # Counter({'jakdu': 1, 'sory': 1, 'kim': 1, 'ahn': 1})
print(counter2) # Counter({'jakdu': 1, 'kim': 1, 'ahn': 1})
print(counter1 - counter2) # Counter({'sory': 1})
from collections import Counter
cnt = Counter(a=5 , b=3)
cnt_list1 = list(cnt)
cnt_list2 = list(cnt.elements())
print(cnt_list1) # ['a', 'b']
print(cnt_list2) # ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'b']