World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITian's, only for AI Learners.
Implement the filter, map and reduce functions in python and give some examples
import functools def f(x): return x % 2 != 0 and x % 3 != 0 # number not divided by 2 and 3 print(list(filter(f, range(2,25)))) # filter function def cube(x): return x*x*x # cube of number print(list(map(cube, range(1,11)))) # map function def add(x,y): return x+y # addition of two number print(functools.reduce(add, range(1,11))) # reduce fuction
Output
[5, 7, 11, 13, 17, 19, 23] [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] 55