DEV Community


Discussion on: Map vs List comprehension in Python

fractionalray profile image

I just have a quick question. What version of python are you using? The reason I am asking is due to our own experiments with map vs list comprehensions differ based on python2 and python3.


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 :))