What's returns map() and filter()? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's returns map() and filter()?

I tried to print result of using map or filter function but got error!

11th Jul 2019, 2:33 PM
Артём Чусовитин
Артём Чусовитин - avatar
7 Answers
+ 7
Theophile, output for "print(map(int, ["2", "3", "10"]))" is "<map object at 0x682e28c>"
11th Jul 2019, 5:55 PM
Lothar
Lothar - avatar
+ 2
They return map or filter objects. If you want to get the list, you have to do something like : list(map(int, liste)) #returns a list
11th Jul 2019, 3:34 PM
Théophile
Théophile - avatar
+ 1
Filter is a function that filter an array of a condition made by the programmer, map is to apply a function in the entire array. Could you show the code to see where is the error?
11th Jul 2019, 3:34 PM
Viktor Lenz
Viktor Lenz - avatar
+ 1
Why i can't print filter or map object? I want see exactly result of using map or filter function, not the list, that i will get if use list(map or filter)
11th Jul 2019, 4:00 PM
Артём Чусовитин
Артём Чусовитин - avatar
+ 1
print(map(int, ["2", "3", "10"]))
11th Jul 2019, 5:00 PM
Théophile
Théophile - avatar
+ 1
Lothar, thanks
11th Jul 2019, 6:16 PM
Артём Чусовитин
Артём Чусовитин - avatar
+ 1
you can also iterate over map and filter objects.. for i in map(int, ["2", "3", "10"]): print(i) you can also also nest the functions in case you’re dealing with nested iterables😀
12th Jul 2019, 2:36 AM
Choe
Choe - avatar