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 #1447

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

solution #1447

wants to merge 1 commit into from

Conversation

Bombardier256
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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()

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:

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants