[Python-Dev] Add a "transformdict" to collections

Paul Moore p.f.moore at gmail.com
Tue Sep 10 23:12:51 CEST 2013


On 10 September 2013 20:59, MRAB <python at mrabarnett.plus.com> wrote:
>> try:
>>      del d[k]
>> finally:
>>      d[k] = v
>>
> That would raise a KeyError is the key was missing. A better way is:
>
> d.pop(k, None)

Sorry, I was thinking of try...except: pass. But pop is indeed better.
Teach me to code stuff on the fly without testing :-)
Paul


More information about the Python-Dev mailing list