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' #1387

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
14 changes: 11 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from typing import Callable
from collections.abc import Callable


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

def wrapper(*args) -> Callable:
if args not in storage:

Choose a reason for hiding this comment

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

In many cases , it is better not to use not, because we always thinking if something is in but not is not in. But a it's a minor thing, that can save you a 3 symbols xD
By the way, it's opinion from my side for this task, sometimes we really need to check not in because it looks better with variable names and task requirements.
At that task, if you swap you if code and else to avoid using not, nothing will change logically!

print("Calculating new result")
return storage.setdefault(args, func(*args))
else:
print("Getting from cache")
return storage.get(args)

Choose a reason for hiding this comment

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

Try to rewrite wrapper not using a duplicated return, without duplicating it

return wrapper

Choose a reason for hiding this comment

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

Always add a blank line at the end of the file.

Copy link
Author

Choose a reason for hiding this comment

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

Yeh, sure, but it is there (flake8 always push me to do this)