On 7/9/07, tav <[EMAIL PROTECTED]> wrote: > setdefault's ability to return current value is also a very useful > functionality and has saved writing: > > if key not in dict: > value = <compute-value> > dict[key] = value > > with the simpler: > > value = dict.setdefault(key, <compute-value>) > > Is there a better way to do the above without .setdefault?
Those are not equivalent, as the form using setdefault() *always* evaluates <compute-value> while the other form only evaluates it when needed. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
