Created
October 30, 2013 10:57
-
-
Save simonvc/7230732 to your computer and use it in GitHub Desktop.
python dictionary has a list or get an empty (but iterable) list
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
| >>> for x in a.get('a list'): | |
| ... print x | |
| ... | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| >>> for x in a.get('b list'): | |
| ... print x | |
| ... | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| TypeError: 'NoneType' object is not iterable | |
| >>> for x in (a.get('b list') or []): | |
| ... print x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment