From b27901d91f46dcf42231ce9f98aba94dd1513c57 Mon Sep 17 00:00:00 2001 From: Diana Zatvarska Date: Wed, 13 Nov 2024 14:34:50 -0800 Subject: [PATCH] 'Solution' --- app/main.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 4c4aa7ba..2e506fdb 100644 --- a/app/main.py +++ b/app/main.py @@ -1,9 +1,16 @@ from typing import Callable, Any -def cache(func: Callable) -> Callable: +def cache(numero: int) -> Any: def wrapper(*args, **kwargs) -> Any: - result = func(*args, **kwargs) - return result + def inner(func: Callable) -> Any: + results = [] + for _ in range(numero): + results.append(func(*args, **kwargs)) + for result in results: + if results.count(result) > 1: + print(f"Getting from cache {result}") + else: + print(f"Calculating new result {result}") + return inner return wrapper -