MAP, FILTER, REDUCE Functions


print("----------------------------MAP-----------------------------------")

def sq(a):
return a*a
def cube(a):
return a*a*a

ks=[sq,cube]

for i in range(1,5+1):
val1=list(map((lambda x:x(i)),ks))
print(val1)

print("---------------------------FILTER-----------------------------------")

lst=[1,2,3,4,5,6,7,8,9]

def is_greater_5(p):
return p>5

print(list(filter(is_greater_5,lst)))


print("---------------------------REDUCE-----------------------------------")
from functools import reduce

lst=[1,2,3,4,5,6,7,8,9]

k=reduce((lambda x,y:x+y),lst)

print(k)

Comments

Popular posts from this blog

React Installation with Vite and Tailwind css (Steps to Installation)

Insert Data In mongoDb

Class methods as an alternative Constructor