#!/usr/bin/env python class A: pass cache = {} def memo(c): if not c in cache: cache[c] = c return cache[c]() print A() print A() print A() print A()