- The defaultdict in contrast will simply create any items that you try to access (provided of course they do not exist yet).The defaultdict is also a dictionary-like object and provides all methods provided by a dictionary.
Syntax-
collections.defaultdict()
Without defaultdict-
program-
x=dict()
print(x['a'])
x=dict()
TypeError: 'Counter' object is not callable
import collections
x=collections.defaultdict(object)
print(x['a'])
<'object object at 0x0000022EB431C740>