On 10 September 2013 20:59, MRAB <[email protected]> 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
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to