BadPython.com

Suggestion for "Not using defaultdict"

Use Defaultdict or (even better) Counter
            
datas = [1, 2, 3, 4, 2, 3, 4, 1, 5]

# Either use defaultdict
from collections import defaultdict
d = defaultdict(int)

for k in datas:
    d[k] += 1

# Or in situations like this just use a counter. It's self documenting and
#   avoids exceptions being thrown if you index on something not in the dict
from collections import Counter

d = Counter(datas)