Referring to this Python List Comprehension Vs. Map question, can someone explain why List Comprehensions gives better results over map
when list comprehension
All your timing results can be explained by theses facts:
CPython has a rather high function call overhead.
map(f, it)
is slightly faster than [f(x) for x in it]
.
The first version of your code does not define a function at all, so there is no function call overhead. The second version needs to define a function, ,so there is function call overhead in every iteration. The third version is completely equivalent to the second one – functions and lambda expressions are the same thing. And the last version is even slower according to fact 2.