collections pop python code example
Example 1: python counter
>>> Counter('abracadabra').most_common(3)
[('a', 5), ('r', 2), ('b', 2)]
Example 2: python counting dictionary
counts = dict()
for i in items:
counts[i] = counts.get(i, 0) + 1
>>> Counter('abracadabra').most_common(3)
[('a', 5), ('r', 2), ('b', 2)]
counts = dict()
for i in items:
counts[i] = counts.get(i, 0) + 1