Skip to content

Commit

Permalink
Remade dictionary methods, removed excessive variables
Browse files Browse the repository at this point in the history
  • Loading branch information
julia4406 committed Nov 26, 2024
1 parent c8da437 commit d242dd1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from typing import Callable
from collections.abc import Callable


def cache(func: Callable) -> Callable:
cached_data = {}
storage = {}

def wrapper(*args, **kwargs) -> Callable:
parameters = tuple(args)
if parameters not in cached_data.keys():
result = func(*args, **kwargs)
cached_data[parameters] = result
def wrapper(*args) -> Callable:
if args not in storage:
print("Calculating new result")
return result
return storage.setdefault(args, func(*args))
else:
print("Getting from cache")
return cached_data.get(parameters)
return storage.get(args)
return wrapper

0 comments on commit d242dd1

Please sign in to comment.