Explain map & filter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Explain map & filter

11th Nov 2016, 9:57 AM
Djaber Meghar
Djaber Meghar - avatar
2 Answers
+ 4
x = [x for x in range(1,10)] # original array print(x) # array with each element squared print(tuple(map(lambda y:y**2,x))) # filter out he odd elements print(tuple(filter(lambda y:y%2==0,x))) both functions work on an array of elements with the difference being that map will apply a function on each element and filter will filter out the elements which does not meet the given criteria (in this case, not even numbers) refer to the code above as an example (can run it in this app)
11th Nov 2016, 10:41 AM
Burey
Burey - avatar
0
thank u
11th Nov 2016, 10:56 AM
Djaber Meghar
Djaber Meghar - avatar