Created
March 25, 2013 17:01
-
-
Save glennzw/5238689 to your computer and use it in GitHub Desktop.
Python dicts - adding if not exist
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
#BAD: | |
if tbl not in all_data: | |
all_data[tbl] = data | |
else: | |
all_data[tbl] += data | |
#GOOD: | |
all_data.setdefault(tbl, []).extend(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment