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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
29 changes: 27 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,30 @@


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

def wrapper(*args, **kwargs) -> None:
Gleb1395 marked this conversation as resolved.
Show resolved Hide resolved
flag = True

Choose a reason for hiding this comment

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

Remove this flag variable

while flag:
data_iterable = tuple(

Choose a reason for hiding this comment

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

include kwargs as well

[item for item in args if isinstance(item, (int, str, float))]
)
if data_iterable not in cache_dict:
print("Calculating new result")
cache_dict[data_iterable] = func(*args, **kwargs)
return cache_dict[data_iterable]
else:

Choose a reason for hiding this comment

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

else operator is redundant. remove it

Copy link
Author

Choose a reason for hiding this comment

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

If I delete else how can I get the cached element back?

print("Getting from cache")
return cache_dict[data_iterable]

return wrapper


@cache
def long_time_func(a: int, b: int, c: int) -> int: # NOQA VNE001
return (a ** b ** c) % (a * c)

Choose a reason for hiding this comment

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

Please remove those examples from PR



@cache
def long_time_func_2(n_tuple: tuple, power: int) -> int:
return [number ** power for number in n_tuple]
Gleb1395 marked this conversation as resolved.
Show resolved Hide resolved
Loading