Thursday, August 27, 2020

What is Map, Filter and Reduce in python full source code of project available on Eaglesoft.

#note: source code is commited first revmove comments command to run
#Developed by Eaglesoft programmers
#--------------MAP---------------------
"""
lis=["45","45","5","80","04"]
lis = list(map(int,lis))
lis[1]=lis[1]+5
print(lis[1])
def func(x):
return x*x


lis=["45","45","5","80","04"]
lis = list(map(int,lis))
lis=list(map(lambda x:x*x,lis))
print(lis)
def squre(a):
return a*a
def cube(a):
return a*a*a
func=[squre,cube]
for i in range(5):
val=list(map(lambda x:x(i),func))
print(val)
"""
# ---------------FILTER---------------------
"""
def is_greater_5(num):
return num>5
list_1=[1,2,3,4,5,6,7,8,9]
list_1=list(filter(is_greater_5,list_1))
print(list_1)
"""
#---------------FILTER---------------------
from functools import reduce
list1=[1,2,3,4,5]


#sove with more lines command
#num=0
#for i in list1:
# num=num+i

num=reduce(lambda x,y:x+y,list1)
print(num)

No comments:

Post a Comment