+ 3

Why does the map function prints true/false and the filter prints values. Isn't it supposed to be vice-versa?

https://code.sololearn.com/cyDgfVN2Uu24/?ref=app

16th Jan 2022, 9:09 AM
Uchiha Madara
Uchiha Madara - avatar
4 Respostas
+ 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))))
17th Jan 2022, 8:47 PM
Mafdi
Mafdi - avatar
+ 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.
16th Jan 2022, 10:32 AM
A͢J
A͢J - avatar
+ 3
Uchiha Madara 1 % 2 == 0 False 2 % 2 == 0 True 3 % 2 == 0 False 4 % 2 == 0 True Which map returns
23rd Jan 2022, 2:10 PM
A͢J
A͢J - avatar
+ 2
But why does it print True/False?
16th Jan 2022, 12:34 PM
Uchiha Madara
Uchiha Madara - avatar