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