python에서 Counter를 이용하면 list로 받은 값들의 개수를 계산한 해서 아래와 같이 결과를 받을 수 있다.

from collections import Counter
Counter(['apple','red','apple','red','red','pear'])
Counter({'red': 3, 'apple': 2, 'pear': 1})

+ Recent posts