defaultdict is not defined
>>> import collections
>>> d = collections.defaultdict(int)
>>> d
defaultdict(<type 'int'>, {})
It might behoove you to read about the import
statement.
You're not importing defaultdict
. Do either:
from collections import defaultdict
or
import collections
d = collections.defaultdict(list)