Origins of Python's “Functional” Features (2009)
python-history.blogspot.com
python-history.blogspot.com
I mean, what do you gain from
map(lambda x: a*x, s)
over [a*x for x in s]?
But as far as I can understand this article, map and lambda are earlier than list comprehension. Is that true? $ python3
>>> [2 * x for x in [1, 2, 3]]
[2, 4, 6]
>>> map(lambda x: 2 * x, [1, 2, 3])
<map object at 0x7f160f535438>`(2 * x for x in [1, 2, 3])`
This is functionally (pun intended) equivalent to `map(lambda x: 2 * x, [1, 2, 3])`
It's useful to have map as a first-class function that you can pass to another function:
def operate_on_two_things(hof):
return (hof([1, 2, 3], lambda x: x + 1),
hof(("A", "B"), lambda y: y + "A")))
operate_on_two_things(map)
(trivial example, but it hopefully makes the point - it's harder to do that with a list comprehension)