Skip to content

Commit

Permalink
'Solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dizatvarska committed Nov 14, 2024
1 parent b27901d commit e30e510
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from typing import Callable, Any


def cache(numero: int) -> Any:
def cache(func: Callable) -> Any:
results = {}

def wrapper(*args, **kwargs) -> Any:
def inner(func: Callable) -> Any:
results = []
for _ in range(numero):
results.append(func(*args, **kwargs))
for result in results:
if results.count(result) > 1:
print(f"Getting from cache {result}")
else:
print(f"Calculating new result {result}")
return inner
if args in results:
print(f"Getting from cache {results[args]}")
else:
result = func(*args)
results[args] = result
print(f"Calculating new result {result}")
return wrapper

0 comments on commit e30e510

Please sign in to comment.