Using Dictionary get method to return empty list by default returns None instead

To solve this you should use Python’s defaultdict. The first time you use a key that doesn’t exist, the argument to the defaultdict constructor is used to create a value (in this case, a list).

http://docs.python.org/library/collections.html#defaultdict-examples

from collections import defaultdict 

d = defaultdict(list)
for i in range( 0, 10 ):
    for j in range( 0, 100 ):
        d[i].append( j )

You can also pass a function as the argument to defaultdict if you want to do anything more elaborate.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)