Hacker News new | ask | show | jobs
by randlet 5393 days 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#collecti...