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

ready #1356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

ready #1356

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
24 changes: 22 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,25 @@


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

Choose a reason for hiding this comment

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

There is a typo in the variable name resalt_func. It should be result_func to be more descriptive and correct.

i = [0]

def wrapper(*args) -> any:

if args not in cache_args:
cache_args[i[0]] = args
resalt = func(*args)

Choose a reason for hiding this comment

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

There is a typo in the variable name resalt. It should be result to be more descriptive and correct.

resalt_func[i[0]] = resalt
print("Calculating new result")
i[0] += 1
return resalt

else:
print("Getting from cache")
for key, value in cache_args.items():
if value == args:
args_key = key
return resalt_func[args_key]
Comment on lines +21 to +24

Choose a reason for hiding this comment

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

The loop to find args_key is inefficient. Consider storing the result directly in the cache with args as the key instead of using an index. This will simplify the retrieval process and improve efficiency.


return wrapper
Loading