<dict>.setdefault()
John J. Lee
jjl at pobox.com
Thu Jul 31 13:01:51 EDT 2003
Tino Lange <tl_news at nexgo.de> writes:
[...]
> This is not what I expected - why evaluate the second argument if it's
> not needed?
[...]
Because that's the way Python always does function calls?
> Is this really by design?
Yes.
> If there's a complicated, expensive to
> calculate/build 2nd argument (maybe a function call) then it's also
> quite ineffective to evaluate it just to throw away...
Don't, then. :-) Use key in dict, or dict.has_key(key).
John
More information about the Python-list
mailing list