Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 15, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/fd5cb4905fd5f1b1558f65b74c2d1f59 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/fd5cb4905fd5f1b1558f65b74c2d1f59 to your computer and use it in GitHub Desktop.
from collections import defaultdict
#default_factory is not mentioned
d=defaultdict()
d['a']=1
d['b']=2
print (d)#Output:defaultdict(None, {'a': 1, 'b': 2})
print (d['a'])#Output:1
# key 'c' doesn't exists in the dictionary,it raises KeyError
print (d['c'])#Output:KeyError: 'c'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment