-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
ready #1356
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,25 @@ | |
|
||
|
||
def cache(func: Callable) -> Callable: | ||
# Write your code here | ||
pass | ||
cache_args = {} | ||
resalt_func = {} | ||
i = [0] | ||
|
||
def wrapper(*args) -> any: | ||
|
||
if args not in cache_args: | ||
cache_args[i[0]] = args | ||
resalt = func(*args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a typo in the variable name |
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop to find |
||
|
||
return wrapper |
There was a problem hiding this comment.
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 beresult_func
to be more descriptive and correct.