2 ms·
map and lambda predate list comprehensions, yes. It's useful to have map as a first-class function that you can pass to another function: def operate_on_t
by lmm 12y ago
map and lambda predate list comprehensions, yes.
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)