Counting is a common dictionary pattern:
def count_items(items):
counts = {}
for item in items:
if item in counts:
counts[item] += 1
else:
counts[item] = 1
return counts
Or more elegantly with get():
def count_items(items):
counts = {}
for item in items:
counts[item] = counts.get(item, 0) + 1
return counts
The get(item, 0) returns if the item isn't in the dictionary yet. Then we add .