Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #1382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
14 changes: 12 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache_list dictionary is used to store cached results. However, using mutable types (like lists) as keys in a dictionary will raise a TypeError. Ensure that the arguments used as keys are immutable types, such as tuples.


def storage(*args, **kwargs) -> int:
if args not in cache_list.keys():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking if args not in cache_list.keys() is unnecessary. You can directly check if args not in cache_list: which is more efficient.

cache_list[args] = func(*args, **kwargs)
print("Calculating new result")
else:
print("Getting from cache")

return cache_list[args]

return storage
Loading