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]
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.
+ 1
Thanks all
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.