***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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6cc0a374-a958-471f-a95d-614ba619823a/image.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/52b553a3-243b-43ca-bc32-2caf96ec0ee6/image.png