On Sun, 17 Apr 2011 16:21:53 +1200 Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote: > My idiom for fetching from a cache looks like this: > > def get_from_cache(x): > y = cache.get(x) > if not y: > y = compute_from(x) > cache[x] = y > return y
I prefer not to create and destroy objects needlessly. def get_from_cache(x): if not x in cache: cache[x] = compute_from(x) return cache[x] -- D'Arcy J.M. Cain <da...@druid.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list