In 2.7 and 3.1, there is the special Counter
(dict
subclass) for this purpose.
>>> from collections import Counter
>>> Counter(['apple','red','apple','red','red','pear'])
Counter({'red': 3, 'apple': 2, 'pear': 1})
In 2.7 and 3.1, there is the special Counter
(dict
subclass) for this purpose.
>>> from collections import Counter
>>> Counter(['apple','red','apple','red','red','pear'])
Counter({'red': 3, 'apple': 2, 'pear': 1})