-
-
Save IndhumathyChelliah/63b9fc7566dfe98d889f3e5835e7916c 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 list class | |
d=defaultdict(list) | |
d['a']=1 | |
d['b']=2 | |
print (d)#Output:defaultdict(<class 'list'>, {'a': 1, 'b': 2}) | |
print (d['a'])#Output:1 | |
# key 'c' doesn't exists in the dictionary,it returns the default value of list which is []. | |
print (d['c'])#Output:[] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment