11 Sep
2013
11 Sep
'13
2:42 a.m.
On 10 September 2013 20:59, MRAB
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