Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
from typing import Callable
from typing import Callable, Any
from functools import wraps


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

@wraps(func)
def wrapper(*args) -> Any:
key = args
if key not in results_dict:
results_dict[key] = func(*args)
print("Calculating new result")
else:
print("Getting from cache")
return results_dict[key]

return wrapper


@cache
def long_time_func(num1: int, num2: int, num3: int) -> int:
result = (num1 ** num2 ** num3) % (num1 * num3)
return result


@cache
def long_time_func_2(n_tuple: tuple, power: int) -> int:
return [number ** power for number in n_tuple]
Loading