Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 15, 2020 20:05
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/63b9fc7566dfe98d889f3e5835e7916c to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/63b9fc7566dfe98d889f3e5835e7916c to your computer and use it in GitHub Desktop.
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