Skip to content

Instantly share code, notes, and snippets.

@prayashm
Created May 30, 2018 10:47
Show Gist options
  • Save prayashm/08aeea141363a2cf97450292d4b09948 to your computer and use it in GitHub Desktop.
Save prayashm/08aeea141363a2cf97450292d4b09948 to your computer and use it in GitHub Desktop.
Using Defaultdict
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