I'm Brett Slatkin and this is where I write about programming and related topics. Check out my favorite posts if you're new to this site. You can also 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-2016 Brett Slatkin