I'm Brett Slatkin and this is where I write about programming and related topics. You can contact me here or view my projects.

05 June 2013

Shortest memo cache

class Memo(dict): \
get = lambda s, k: (len(s) > 1000 and s.clear()) or \
  (k in s and s[k]) or s.setdefault(k, s.f(k)); \
f = lambda s, k: # your code here
© 2009-2024 Brett Slatkin