Map, filter & Reduce #PYTHON NOTES 4
""" map(function, implimentation) --> n for n result """
num = [2,3,4,5,8,9,2,3]
numSq = list(map(lambda x: x**2, num))
print(numSq)
# avoiding use of forloops
""" filter ---> +1 for n result"""
x = [2,4,9,6,7,0,2,5,4]
y = list(filter(lambda x: x >= 5, x))
print(y)
""" reduce --> dones process in cummalative way --> 1 for n result"""
from functools import reduce
f1 = [1,2,3,4,5]
f2 = reduce(lambda x,y : x*y, f1)
print(f2)

Comments
Post a Comment