I was wondering the reason why there is no list.map() in the Python standard library.
There are alternatives, like map(function,iterable), and list comprehensions.
I cannot find the PEP (design document) that explains the whys of choosing map instead of implementing list.map()
Suppose we have a list like this:
foo = [1,2,3,4,5,6]
I believe this code:
foo.map(function)
# or
foo.map(lambda x: x*2)
Is more readable than:
least_readable = list(map(lambda x: x*2, foo))
least_readable = list(map(multiply_by_two, foo))
This looks readably enough for me
it_readable_enough_for_me = [multiply_by_two(x) for x in foo]
This looks more readable to me but doesn't exist:
does_not_exist = foo.map(multiply_by_two)
I believe that if that does not exist, there must be a reason for it.
Not just because map(function,iterable) is more general. I guess there must be an important reason behind that I don't see.
None.
PEP 201, the 2nd ever stable implemented PEP, says:
The
map
function is defined inbltinmodule.c
, added in commit a6c603. The previous location isitertoolsmodule.c
, which was originally introduced in commit 96ef81 on 1st Feb 2003. There are no PEPs adding this feature up until that date.According to Wikipedia: