The Counting Pattern
Count how many times each item appears:
def histogram(s):
d = {}
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
histogram('brontosaurus') → {'b': 1, 'r': 2, 'o': 2, ...}
This pattern is everywhere: counting words, votes, frequencies, etc.