The map()
function applies a given function to each item of an iterable. When this function is a lambda
, especially a
simple one, the resulting code can sometimes be less readable than its comprehension or generator expression equivalent. For example: A comprehension
like [x * 2 for x in nums]
is more straightforward to read and understand at a glance than list(map(lambda x: x * 2, nums))
.
The logic is more self-contained and doesn’t require mentally parsing the map
and lambda
separately.
Using map()
could also have an impact on performance. While map()
can be very efficient when used with built-in functions
or pre-defined functions written in C, the use of a Python lambda
introduces function call overhead for each element in the iterable.