DEV Community


Discussion on: Map vs List comprehension in Python

alanmarazzi profile image

The timing in the example above are wrong. The map example generates a new function at every loop, while the list comprehension just multiplies the result.

If you define a function outside or use one already available, map should actually be slightly faster (without taking into account that map is lazy, so if you don't need that value you'll have the best performance possible :))