Just so I understand things correctly, apart from the obvious benefits of using defaultdict(), were there reasons directly related to your implementation that dictated the use of defaultdict()?

I guess I'll make this a seperate commit then (add defaultdict() usage first, then merge your pull request).