|
@@ -47,6 +47,33 @@ def aggregation(func, sequence):
|
|
return new_list
|
|
return new_list
|
|
|
|
|
|
|
|
|
|
|
|
+def aggregation_2(func, sequence):
|
|
|
|
+ new_list = []
|
|
|
|
+
|
|
|
|
+ foo = func(sequence[0], sequence[1])
|
|
|
|
+ new_list.append(foo)
|
|
|
|
+
|
|
|
|
+ for x in range(2, len(sequence)):
|
|
|
|
+ foo = func(foo, sequence[x])
|
|
|
|
+ new_list.append(foo)
|
|
|
|
+
|
|
|
|
+ return new_list[-1]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def aggregation_3(func, sequence, initial=None):
|
|
|
|
+ new_list = []
|
|
|
|
+
|
|
|
|
+ if initial != None:
|
|
|
|
+ foo = initial
|
|
|
|
+ for x in sequence:
|
|
|
|
+ foo = func(foo, x)
|
|
|
|
+ else:
|
|
|
|
+ foo = func(sequence[0], sequence[1])
|
|
|
|
+ for x in range(2, len(sequence)):
|
|
|
|
+ foo = func(foo, sequence[x])
|
|
|
|
+
|
|
|
|
+ return foo
|
|
|
|
+
|
|
|
|
|
|
"""Для теста"""
|
|
"""Для теста"""
|
|
def square(num):
|
|
def square(num):
|
|
@@ -64,6 +91,14 @@ def is_even(num):
|
|
def get_add(x, y):
|
|
def get_add(x, y):
|
|
return x + y
|
|
return x + y
|
|
|
|
|
|
|
|
+def get_max(x, y):
|
|
|
|
+ return max(x, y)
|
|
|
|
+
|
|
|
|
+def get_product(x, y):
|
|
|
|
+ return x * y
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
def main():
|
|
def main():
|
|
# print(compute([inc, dec, square], 10, 20, 30, 40))
|
|
# print(compute([inc, dec, square], 10, 20, 30, 40))
|
|
@@ -79,9 +114,13 @@ def main():
|
|
|
|
|
|
# print(filter_collection(lambda x: x not in 'aeiou', 'I never heard those lyrics before'))
|
|
# print(filter_collection(lambda x: x not in 'aeiou', 'I never heard those lyrics before'))
|
|
|
|
|
|
|
|
+ # print(aggregation(get_add, [5, 2, 4, 3, 5]))
|
|
|
|
|
|
- print(aggregation(get_add, [5, 2, 4, 3, 5]))
|
|
|
|
|
|
+ # print(aggregation_2(get_max, [1, 4, 5, 7, 6, 5, 8, 10, 5]))
|
|
|
|
+ # print(aggregation_2(get_add, [5, 2, 4, 3, 5]))
|
|
|
|
|
|
|
|
+ # print(aggregation_3(lambda x, y: x + y, [4, 5, 6], initial=100))
|
|
|
|
+ print(aggregation_3(get_product, [2, 5, 10, 1, 2]))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
main()
|
|
main()
|