-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_func.py
More file actions
32 lines (31 loc) · 995 Bytes
/
map_func.py
File metadata and controls
32 lines (31 loc) · 995 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
import functools
# --------------------------------------map function ------------------------------------
list1=[1,2,3,4]
for i in range (len(list1)):
list1[i] = int(list1[i])
map(int,list1)
list1[0] = list1[0]+list1[1]+list1[2]+list1[3]
list1[1] = list1[0]+list1[1]+list1[2]+list1[3]
print(list1)
list1 = [1,2,3,4,5,6,7,8,9]
def square (num):
return num * num
def cube (num):
return num*num
func = [square,cube]
for i in range (len(list1)):
value = list(map(lambda x:x(i),func))
print(value)
# ------------------------------------filter fuction--------------------------------------
list1 = [1,2,3,4,5,6,7,8,9]
def greater_then(num):
return num > 5
def equal (num):
return num == 2
a = list(filter(equal,list1))
a1 = list(filter(greater_then,list1))
print(a,a1)
# ----------------------------------reduce function -----------------------------------------
list1=[1,2,3,4]
print(functools.reduce(lambda x,y: x*y,list1))
print(functools.reduce(lambda x,y:x+y,list1))