Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
D1st3f committed Sep 26, 2023
1 parent 5891c38 commit 495701b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@


def cache(func: Callable) -> Callable:
# Write your code here
pass
cached_info = {}

def inner(*args, **kwargs) -> int:
# Щоб унеможливити зміну ключа кешу, довелося перетворити
# ключові аргументи у tuple
set_key = (args, tuple(sorted(kwargs.items())))
if set_key in cached_info:
print("Getting from cache")
return cached_info[set_key]
result = func(*args, **kwargs)
cached_info[set_key] = result
print("Calculating new result")
return result
return inner

0 comments on commit 495701b

Please sign in to comment.