More often that not I have trouble grasping the question. There is side effect of adding new key value pair but anyways:
>>> key = 'oh my' >>> d = {'meaning of life': 42} >>> d.setdefault(key, key) 'oh my' >>> d.setdefault('meaning of life', 'no way') 42 >>> d {'meaning of life': 42, 'oh my': 'oh my'}With another side effect:
>>> key = 'oh no' >>> d = {'meaning of life': 42} >>> d.pop(d.setdefault(key, key)) 'oh no' >>> d {'meaning of life': 42} >>> d.pop(d.setdefault('meaning of life', 'oh no')) -------------------------------------------------------------------------- /.../ ----> 1 d.pop(d.setdefault('meaning of life', 'oh no')) KeyError: 42
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.