Skip to content

Instantly share code, notes, and snippets.

@pupadupa
Created April 10, 2013 22:48
Show Gist options
  • Save pupadupa/5359142 to your computer and use it in GitHub Desktop.
Save pupadupa/5359142 to your computer and use it in GitHub Desktop.
defaultdict example
>>> from collections import defaultdict
>>> dd = defaultdict(str)
>>> dd
defaultdict(<type 'str'>, {})
>>> dd['asd']
''
>>> int(dd['asd'] or 0)
0
>>> dd['aaa']=123
>>> int(dd['aaa'] or 0)
123
>>> int(dd['aaaa'] or 0)
0
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment