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