From 2a2126fc508288fb71076fd4c0ef1aa96ede6f98 Mon Sep 17 00:00:00 2001 From: Damodar Date: Fri, 22 Sep 2023 00:01:34 +0300 Subject: [PATCH] new_Solution --- app/main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/main.py b/app/main.py index 7d61e69e..1dc520d4 100644 --- a/app/main.py +++ b/app/main.py @@ -1,23 +1,22 @@ from typing import Callable -results_list = [] - def cache(func: Callable) -> Callable: + results_list = [] + def inner(*args) -> Callable: - global results_list + nonlocal results_list for result in results_list: - if (result["arguments"] == [*args] - and result["id_func"] == id(func)): + if result["arguments"] == [*args]: print("Getting from cache") return result["result_func"] results_list += [ { "arguments": [*args], - "result_func": func(*args), - "id_func": id(func) + "result_func": func(*args) } ] print("Calculating new result") return results_list[-1].get("result_func") + return inner