News for hackers. Stuff that matters.
Re:Beej’s Guide to C Programming [pdf] by klyrs on Saturday April 24, 2021 @12:41PM (#26926218)
It's a feature! Use this memoization pattern and you'll never forget it

  def foo(x, cache={}):
    if x in cache:
      return cache[x]
    val = cache[x] = x*x+1
    return val
But, be warned, there's no mechanism for cache eviction; use @lru_cache if you don't know ahead of time that x will take a reasonably small number of values

There are no comments on this comment yet.