Sure, I was just shuffling around what was there but defaultdict is definitely called for, here. Not sure why I didn't do it in the first place, probably was in a rush.