I never understood why python had lambda and map when list comprehension does exactly the same thing in a pythonic way. I mean, we don't ask Haskell to adopt list comprehension.
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?
Python's [list] comprehension syntax was directly inspired by Haskell's list comprehension syntax. And it's also widely (I'd argue) considered to be the Pythonic way of composing lists (and other iterables), rather than using map. It's provenance doesn't detract from that.
map and related functions such as reduce and filter, along with lambda have been around since python 1.x days (not sure how far back, I started with 1.5.2). Comprehensions were added in Python 2.0.
I mean, what do you gain from
over But as far as I can understand this article, map and lambda are earlier than list comprehension. Is that true?