diff --git a/lib.py b/lib.py index c6c4720..d310ea3 100644 --- a/lib.py +++ b/lib.py @@ -1,5 +1,15 @@ #!/usr/bin/env python3 +def memoize(f): + cache = dict() + def memf(*args): + key = tuple(args) + if key not in cache: + cache[key] = f(*args) + return cache[key] + return memf + + class Graph(dict): nodes = dict.keys