In Python it\'s annoying to have to check whether a key is in the dictionary first before incrementing it:
if key in my_dict: my_dict[key] += num else: m
transform:
if key in my_dict: my_dict[key] += num else: my_dict[key] = num
into the following using setdefault:
my_dict[key] = my_dict.setdefault(key, 0) + num