+ 3
Why does the map function prints true/false and the filter prints values. Isn't it supposed to be vice-versa?
4 ответов
+ 4
"""
Uchiha Madara
It prints True/False because you are giving a boolean expression / condition.
If the number is divisible by 2 the result is True, else it is False.
try this:
"""
print(list(map(lambda x: x*5, range(10))))
print(list(filter(lambda x: x%5 == 0, range(10))))
+ 4
Uchiha Madara
The filter method doesn't do the same as the map method.
The map method is used to convert each item of an array.
To see change x % 2 == 0 to x % 2
filter method is used to select certain items of an array.
+ 3
Uchiha Madara
1 % 2 == 0 False
2 % 2 == 0 True
3 % 2 == 0 False
4 % 2 == 0 True
Which map returns
+ 2
But why does it print True/False?