3 ms·
You can use the Counter class from the collections module[1] for that as well. >>> from collections import Counter >>> c = Counter() >>> c['foo'] 0 >
by randlet 15y ago
You can use the Counter class from the collections module[1] for that as well.
>>> from collections import Counter
>>> c = Counter()
>>> c['foo']
0
>>> c['bar'] +=1
>>> c['bar']
1
>>>
[1] http://docs.python.org/dev/library/collections.html#collections.Counter http://docs.python.org/dev/library/collections.html#collecti...