-
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
Solution #1393
base: master
Are you sure you want to change the base?
Solution #1393
Conversation
# Testing | ||
print(long_running_function(1, 2)) | ||
print(long_running_function(1, 2)) | ||
print(long_running_function(2, 3)) | ||
print(another_function(3)) | ||
print(another_function(3)) |
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.
Dont push such changes
if args in cache_storage: | ||
print("Getting from cache") | ||
return cache_storage[args] | ||
else: | ||
print("Calculating new result") | ||
result = func(*args) | ||
cache_storage[args] = result | ||
return result |
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.
Try to use only 1 return
|
||
|
||
def cache(func: Callable) -> Callable: | ||
# Write your code here | ||
pass | ||
cache_storage: Dict[Tuple, any] = {} |
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.
Any must be imported as type, any
is a bult-in construction, not a type
pass | ||
cache_storage: Dict[Tuple, any] = {} | ||
|
||
def wrapper(*args) -> any: |
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.
same about any
@@ -1,6 +1,38 @@ | |||
from typing import Callable | |||
from typing import Callable, Dict, Tuple |
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.
You already have dict and tuple in python and can use it for annotation
No description provided.