Counter 사용법

청수동햄주먹·2023년 4월 11일
0

파이썬코딩테스트

목록 보기
24/35
from collections import Counter

xx = Counter("203045")

print(xx.keys()) # ['0', '3', '2', '5', '4']
print(xx.items()) # [('0', 2), ('3', 1), ('2', 1), ('5', 1), ('4', 1)]
print(xx.values()) # [2, 1, 1, 1, 1]
print(xx['1']) # 0

from collections import Counter

Counter.keys()

set과 같은 결과

Counter.items()

(키, 카운트 횟수) 쌍으로 보여줌

Counter.values()

키가 카운트 된 횟수를 보여준다

profile
코딩과 사별까지

0개의 댓글