Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
RadeonT800 committed Oct 31, 2024
1 parent 5891c38 commit 359c6cd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
from typing import Callable
from typing import Callable, Any
import functools


def cache(func: Callable) -> Callable:
# Write your code here
pass
calculated_data = []

@functools.wraps(func)
def wrapper(*args, **kwargs) -> Any:
for value in args:
if isinstance(value, (list, set, dict)):
return None
for args_save, kwargs_save, result_save in calculated_data:
if args_save == args and kwargs_save == kwargs:
print("Getting from cache")
return result_save
result = func(*args, **kwargs)
calculated_data.append((args, kwargs, result))
print("Calculating new result")
return result
return wrapper

0 comments on commit 359c6cd

Please sign in to comment.