|
@@ -34,6 +34,20 @@ def filter_collection(f, collection):
|
|
|
return type(collection)(lst)
|
|
|
|
|
|
|
|
|
+def aggregation(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
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
"""Для теста"""
|
|
|
def square(num):
|
|
|
return num ** 2
|
|
@@ -47,7 +61,8 @@ def dec(num):
|
|
|
def is_even(num):
|
|
|
return num % 2 == 0
|
|
|
|
|
|
-
|
|
|
+def get_add(x, y):
|
|
|
+ return x + y
|
|
|
|
|
|
|
|
|
def main():
|
|
@@ -58,11 +73,14 @@ def main():
|
|
|
# even_numbers = filter_list(is_even, numbers) # берем только четные
|
|
|
# print(even_numbers)
|
|
|
|
|
|
- numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
|
|
- even_numbers = filter_collection(is_even, numbers)
|
|
|
- print(even_numbers)
|
|
|
+ # numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
|
|
+ # even_numbers = filter_collection(is_even, numbers)
|
|
|
+ # print(even_numbers)
|
|
|
+
|
|
|
+ # 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]))
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|