Skip to content

Added functional.py and README for hw6#8

Open
ibragimovaamina wants to merge 2 commits into
mainfrom
hw6_functional
Open

Added functional.py and README for hw6#8
ibragimovaamina wants to merge 2 commits into
mainfrom
hw6_functional

Conversation

@ibragimovaamina

Copy link
Copy Markdown
Owner

No description provided.

@krglkvrmn krglkvrmn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

image

# It returns list of results of sequential application of these functions to the collection of values.

def sequential_map(*args):
*functions, values = [*args] # unpacking input functions and collection of values

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Эта конструкция немного избыточна

Suggested change
*functions, values = [*args] # unpacking input functions and collection of values
*functions, values = args # unpacking input functions and collection of values

while len(values) > 1: # if 0 or 1 input values, returning values immediately
values[1] = function(values[0], values[1])
values = values[1:]
return values

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

На выходе мы получаем список из одного элемента, а нам нужен сам элемент, без списка

Comment on lines +49 to +53
list_of_functions = [*args]
while len(list_of_functions) > 1:
list_of_functions[1] = wrapping_function(list_of_functions[0], list_of_functions[1])
list_of_functions = list_of_functions[1:]
return list_of_functions[0]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Сложна, как насчёт

Suggested change
list_of_functions = [*args]
while len(list_of_functions) > 1:
list_of_functions[1] = wrapping_function(list_of_functions[0], list_of_functions[1])
list_of_functions = list_of_functions[1:]
return list_of_functions[0]
def inner_func(obj):
for func in args:
obj = func(obj)
return obj
return inner_func

return lambda x: outer_func(inner_func(x))

def func_chain(*args):
list_of_functions = [*args]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А зачем тут делать распаковку, в данному случае args уже read-to-use

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