changeset 103:9accc0244e82

created
author 127.0.0.1
date Fri, 06 Dec 2013 23:43:54 +0100
parents c16432ce1be3
children 87fd7a11be5d
files hash6.py
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hash6.py	Fri Dec 06 23:43:54 2013 +0100
@@ -0,0 +1,20 @@
+import functools
+
+def memoize_typed(func):
+    cache = {}
+    @functools.wraps(func)
+    def wrapped(*args):
+        key = args, tuple(type(arg) for arg in args)
+        try:
+            result = cache[key]
+        except KeyError:
+            result = cache[key] = func(*args)
+        return result
+    return wrapped
+
+@memoize_typed
+def show(what):
+    print what
+
+show(1)
+show(1.0)
\ No newline at end of file