Why the output is not in Boolean example :- [True,True] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the output is not in Boolean example :- [True,True]

numbers=[1,2,3,4] result= list(filter(lambda i : i%2==0,numbers)) print(result) output :- [2,4] But i%2==0 expression return boolean value than why the output is in numbers not in boolean example:-[True,True]

9th Apr 2020, 5:35 AM
Rishi
Rishi - avatar
3 Answers
0
How filter works, is that it checks each element if they satisfy a condition (called "predicate"), if not then the element is removed. But the values are not changed. If you want to transform the values, use the map() function.
9th Apr 2020, 5:39 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thanks all
9th Apr 2020, 5:52 AM
Rishi
Rishi - avatar
0
That is because the filter function return the values that complete a condition, so the 2 and 4 are evens so they complete your condition and are returned. I'm practicing English.
9th Apr 2020, 5:42 AM
Jonathan Alvarado
Jonathan Alvarado - avatar