count element in dict python code example
Example 1: how many keys in a dictionary python
> a = {'foo':42, 'bar':69}
> len(a)
2
Example 2: python counting dictionary
counts = dict()
for i in items:
counts[i] = counts.get(i, 0) + 1
> a = {'foo':42, 'bar':69}
> len(a)
2
counts = dict()
for i in items:
counts[i] = counts.get(i, 0) + 1