Development/Python
[Python] How to install and use Counter module : python 중복 카운트
Best Junior
2019. 7. 26. 13:35
작업 환경 : Python2.7 / Linux
python 중복 카운트 예시
>>> from collections import Counter
>>> a = ['123', '234', '345', '123', '345', '456']
>>> Counter(a)
Counter({'345': 2, '123': 2, '234': 1, '456': 1})
1. Counter 모듈 pip 설치
pip install Counter
2. Counter 중복 카운트 테스트
from collections import Counter
Counter(a)
-> Counter({'345': 2, '123': 2, '234': 1, '456': 1})
result['123']
-> 2