Added memoize to lib

master
Tibor Bizjak 2023-03-14 12:44:57 +01:00
parent 8b0cb8d9d7
commit bdb48f0320
1 changed files with 10 additions and 0 deletions

10
lib.py
View File

@ -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