-
-
Save IndhumathyChelliah/c8287ad8a2f99225d2e76866efd54738 to your computer and use it in GitHub Desktop.
This file contains 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 | |
#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