Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 15, 2020 20:12
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/c8287ad8a2f99225d2e76866efd54738 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/c8287ad8a2f99225d2e76866efd54738 to your computer and use it in GitHub Desktop.
from collections import defaultdict
#default_factory is given as user defined function
def func():
return "None"
d=defaultdict(func)
d['a']=1
d['b']=2
print (d)#Output:defaultdict(<function func at 0x015A7808>, {'a': 1, 'b': 2})
print (d['a'])#Output:1
# key 'c' doesn't exists in the dictionary,it returns the default value which is "None"
print (d['c'])#Output:None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment