How to Solve NameError: name 'defaultdict' is not defined -- collections

Solution: Import the 'defaultdict' module

# Add the following line to the top of your code
from collections import defaultdict

 

For more information:
collections defaultdict