> One way to satisfy this would be to redefine setdefault something like > this: > > def setdefault(aDict, aKey, aValue=None, lazy=None): > assert aValue is None or lazy is None > if aKey not in aDict: > aDict[aKey] = (if lazy is None: aValue else: lazy()) > return aDict[aKey] Nice. Nevertheless I keep thinking that current "setdefault" behaviour is not fully documented and counterintuitive :-). So we would need to fix the behaviour or update docs :-p God, you all mutate a fairly simple and concrete consideration into a broad language "lazy evaluation" feature. I'm overhelmed };-) > myDict.setdefault(myKey, lazy=lambda:expensive_function(args)) Nice lambda usage: declare a pseudofunction that calls another function with predefined parameters. Updating my toolbox... :) -- Jesus Cea Avion _/_/ _/_/_/ _/_/_/ jcea@argo.es http://www.argo.es/~jcea/ _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ _/_/_/_/_/ PGP Key Available at KeyServ _/_/ _/_/ _/_/ _/_/ _/_/ "Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/ "El amor es poner tu felicidad en la felicidad de otro" - Leibniz
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4