+ 28

Py: why method "map" have to need "list"?

Python metods

1st Oct 2018, 7:31 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
4 Answers
+ 5
The very idea of map function implies that it has a list as an argument. Mapping a scalar has no sense since you can do it with a simple function. Map means to run a said function through the iterable (list) and map means to return an iterator. Of course your list may consist of one value but it doesn'matter.
1st Oct 2018, 7:39 PM
strawdog
strawdog - avatar
+ 20
strawdog đŸ‡·đŸ‡ș I thought that the map returns a class object. so it must be brought to normal.
1st Oct 2018, 9:12 PM
Friend 4 Goodmen
Friend 4 Goodmen - avatar
+ 3
map used to create a list in Python 2 but was changed in Python 3 to be an iterator, or an object which iterates through an iterable to produce the values one at a time. this prevents duplication of data and thus saves on memory.
8th Oct 2018, 4:12 PM
Kevin Shibley
Kevin Shibley - avatar
+ 1
Friend 4 Goodmen , map function returns a map object (class map), which is an iterator. You can either enclose it into an iterable (like list) or strictly iterate through is values.
1st Oct 2018, 10:44 PM
strawdog
strawdog - avatar