Mercurial > memoize-slides
changeset 101:7ab83fbd6040
created
| author | 127.0.0.1 |
|---|---|
| date | Fri, 06 Dec 2013 23:42:24 +0100 |
| parents | 6fdc4844d284 |
| children | c16432ce1be3 |
| files | hash5.py |
| diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hash5.py Fri Dec 06 23:42:24 2013 +0100 @@ -0,0 +1,19 @@ +import functools + +def memoize(func): + cache = {} + @functools.wraps(func) + def wrapped(*args): + try: + result = cache[args] + except KeyError: + result = cache[args] = func(*args) + return result + return wrapped + +@memoize +def show(what): + print what + +show(1) +show(1.0) \ No newline at end of file
