D'Arcy J.M. Cain wrote:
On Sun, 17 Apr 2011 16:21:53 +1200
Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote:

  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.

How does that create objects needlessly?

 def get_from_cache(x):
   if not x in cache:
     cache[x] = compute_from(x)
   return cache[x]

That looks up the cache *twice* for every access. Mine
only does one lookup when the item is already in the
cache.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to