-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #1447
base: master
Are you sure you want to change the base?
solution #1447
Conversation
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.
Great job on implementing the caching decorator! 🎉 The core functionality is working well, and you've ensured that each decorated function maintains its own cache. Just a small note: there's a typo in the function name wraper
—it should be wrapper
. Also, if you plan to use keyword arguments (kwargs
), remember to convert them to a hashable type for the cache keys. Keep up the good work and happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -2,5 +2,13 @@ | |||
|
|||
|
|||
def cache(func: Callable) -> Callable: | |||
# Write your code here | |||
pass | |||
cache = dict() |
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.
The cache
variable is correctly initialized as a dictionary here. However, ensure that the keys used in this dictionary are hashable. Since args
is a tuple, it is hashable, but if kwargs
are used, you need to convert them to a hashable type (e.g., a tuple of sorted key-value pairs).
pass | ||
cache = dict() | ||
|
||
def wraper(*args, **kwargs) -> int: |
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 function name wraper
. It should be wrapper
.
cache = dict() | ||
|
||
def wraper(*args, **kwargs) -> int: | ||
if args in cache: |
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.
Using args
directly as a key in the cache dictionary is fine since tuples are hashable. However, if you plan to use kwargs
as well, you need to convert them to a hashable type before using them as a key.
No description provided.