Here's where dict.setdefault() could reduce this from 5 lines to one...