Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Last active July 15, 2020 20:30
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/68240135148e0a11e01945ade6b9e51b to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/68240135148e0a11e01945ade6b9e51b to your computer and use it in GitHub Desktop.
from collections import defaultdict
#default_factory is not specified.
d=defaultdict()
d['a']=1
d['b']=2
#default_factory attribute is None.
print (d)#Output:defultdict(None, {'a': 1, 'b': 2})
#Returns the default value for key.If not specified raises keyError.
#print (d.__missing__('a')) #Output:KeyError: 'a'
print (d.__missing__('z'))#Outptu:KeyError: 'z'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment