I’ve always used defaultdicts before the dictionary type itself has a method: setdefault
>> a = {} >>> a.setdefault('x', 0) 0 >>> a {'x': 0}
I’ve always used defaultdicts before the dictionary type itself has a method: setdefault
>> a = {} >>> a.setdefault('x', 0) 0 >>> a {'x': 0}