Skip to content

Instantly share code, notes, and snippets.

@whatisjasongoldstein
Last active December 10, 2015 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatisjasongoldstein/4485980 to your computer and use it in GitHub Desktop.
Save whatisjasongoldstein/4485980 to your computer and use it in GitHub Desktop.
# {}.get()'s second argument only kicks in if there's no key.
# None, '', or falsy values are perfectly okay.
# If you actually want ot fall back to a default, use or.
In [1]: data = {'red':None}
In [2]: data.get('red','backup')
In [3]: data.get('red') or 'backup'
Out[3]: 'backup'
In [4]: data.get('blue','backup')
Out[4]: 'backup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment