Last active
December 10, 2015 20:08
-
-
Save whatisjasongoldstein/4485980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# {}.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