>>> import collections
>>> from collections import Counter >>> import re >>> path = '/usr/share/doc/python-2.7.3/LICENSE' >>> words = re.findall('\w+', open(path).read().lower()) >>> Counter(words).most_common(10) [('2', 97), ('the', 80), ('or', 78), ('1', 76), ('of', 61), ('to', 50), ('and', 47), ('python', 46), ('psf', 44), ('in', 38)]
>>> c = Counter(a=4, b=2, c=0, d=-2) >>> list(c.elements()) ['a', 'a', 'a', 'a', 'b', 'b']
>>> Counter('abracadabra').most_common(3) [('a', 5), ('r', 2), ('b', 2)]