From 6ea01e729b22befd14f24d4f1fb36e81ecc8dab1 Mon Sep 17 00:00:00 2001 From: Myroslava Nezbrytska Date: Wed, 27 Nov 2024 22:58:46 +0200 Subject: [PATCH 1/2] solution --- app/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 68287892..4e226a31 100644 --- a/app/main.py +++ b/app/main.py @@ -2,5 +2,16 @@ def cache(func: Callable) -> Callable: - # Write your code here - pass + result = {} + def wrap(*args): + + if args in result: + print("Getting from cache") + return result[args] + else: + all_in = func(*args) + result[args] = all_in + print("Calculating new result") + return all_in + + return wrap From bdf7a8dd6b662c10031760e01294c4134518c4b0 Mon Sep 17 00:00:00 2001 From: Myroslava Nezbrytska Date: Wed, 27 Nov 2024 23:04:54 +0200 Subject: [PATCH 2/2] fixed flake --- app/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 4e226a31..e1f59eca 100644 --- a/app/main.py +++ b/app/main.py @@ -1,9 +1,10 @@ -from typing import Callable +from typing import Callable, Any def cache(func: Callable) -> Callable: result = {} - def wrap(*args): + + def wrap(*args) -> Any: if args in result: print("Getting from cache")