-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFuncMapAndFilter.py
More file actions
39 lines (31 loc) · 947 Bytes
/
Copy pathFuncMapAndFilter.py
File metadata and controls
39 lines (31 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
'''
Примеры работы map и filter
'''
try:
first_arg, second_arg = map(int, input().split())
except ValueError as e:
print("Input error. Exception type from {0} {1}".
format(
type(e),
"\nThis Script exit with code is '1'")
)
sys.exit(1)
except Exception as e:
print("Type Error: {0}, Error mess:{1}".format(type(e)), e)
sys.exit(1)
print("Сумма {0} + {1} = {2}".format(first_arg, second_arg, first_arg + second_arg))
# Пример фильтра
# Example use mamp
filter_evens = map(int, input('Список на фильтр :').split())
'''
Equals with generator function and list Comprehensions
filter_evens = (int(i) for i in input('Список на фильтр :').split())
'''
def even(x):
if (x % 2 == 0):
return True
return False
evens = filter(even, filter_evens)
for _ in evens:
print("Filtered element from list: {}".format(_))