how to add to a dictionary value or create if not exists
07:18 17 Jul 2014

I want to add to a value in a dictionary storing counters:

d[key] += 1

but sometimes the key will not exist yet. Checking to see if the key exists seems too ugly. Is there a nice and pythonic one liner for this - add if the key exists, or create the value 1 if the key is not in the dict.keys ?

python python-3.x