Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Jejemira committed Oct 6, 2024
1 parent 372fe39 commit e4935e4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ def cache(func: Callable) -> Callable:
save_result = {}

def inner(*args, **kwargs) -> Callable:
key_in_save_result = (func.__name__, args,)
for value in kwargs.values():
key_in_save_result.add(value)
key_in_save_result = (func.__name__, args, tuple(kwargs.items()))
if save_result:
if key_in_save_result in save_result:
print("Getting from cache")
return save_result[key_in_save_result]

print("Calculating new result")
result = func(*args)
result = func(*args, **kwargs)
save_result[key_in_save_result] = result
return result

Expand Down

0 comments on commit e4935e4

Please sign in to comment.