Created
May 30, 2018 10:47
-
-
Save prayashm/08aeea141363a2cf97450292d4b09948 to your computer and use it in GitHub Desktop.
Using Defaultdict
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
from collections import defaultdict | |
new_dict = defaultdict(int) | |
old_dict = {'one': 1, 'two': 2} # One returned from API | |
new_dict.update(old_dict) | |
new_dict['one'] # returns 1 | |
new_dict['not_there'] # returns 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment