From bdb48f032011e7d1d53f9da3cce9c6f01082ba6d Mon Sep 17 00:00:00 2001 From: Tibor Bizjak Date: Tue, 14 Mar 2023 12:44:57 +0100 Subject: [PATCH] Added memoize to lib --- lib.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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