***Syntax:*defaultdict(default_factory)
Parameters:
When the list class is passed as the default_factory argument, then a defaultdict is created with the values that are (empty) list.
from collections import defaultdict
# Defining a dict
d = defaultdict(list)
for i in range(5):
d[i].append(i)
print("Dictionary with values as list:")
print(d)
output:
Dictionary with values as list:
defaultdict(<class 'list'>, {0: [0], 1: [1], 2: [2], 3: [3], 4: [4]})
When the int class is passed as the default_factory argument, then a defaultdict is created with default value as zero.