-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_filter_reduce.py
50 lines (42 loc) · 1.04 KB
/
map_filter_reduce.py
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
40
41
42
43
44
45
46
47
48
49
50
#--------------------------MAP------------------------------
# numbers = ["3", "34", "64"]
# numbers = list(map(int, numbers))
# for i in range(len(numbers)):
# numbers[i] = int(numbers[i])
# numbers[2] = numbers[2] + 1
# print(numbers[2])
# def sq(a):
# return a*a
#
# num = [2,3,5,6,76,3,3,2]
# square = list(map(sq, num))
# print(square)
# num = [2,3,5,6,76,3,3,2]
# square = list(map(lambda x: x*x, num))
# print(square)
# def square(a):
# return a*a
#
# def cube(a):
# return a*a*a
# func = [square, cube]
# num = [2,3,5,6,76,3,3,2]
# for i in range(5):
# val = list(map(lambda x:x(i), func))
# print(val)
#--------------------------FILTER------------------------------
# list_1 = [1,2,3,4,5,6,7,8,9]
#
# def is_greater_5(num):
# return num>5
#
# gr_than_5 = list(filter(is_greater_5, list_1))
# print(gr_than_5)
#--------------------------REDUCE------------------------------
from functools import reduce
list1 = [1,2,3,4,2]
num = reduce(lambda x,y:x*y, list1)
# num = 0
# for i in list1:
# num = num + i
print(num)