DEV Community

qing
qing

Posted on

Quick Tip: List comprehensions are faster than `map()` in most cases (2026)

Quick Tip: List comprehensions are faster than map() in most cases

When it comes to transforming lists in Python, two common approaches are list comprehensions and the map() function. While both can achieve the same result, there's a notable difference in performance.

Let's take a simple example where we want to square all numbers in a list. We can use either a list comprehension or map():

numbers = [1, 2, 3, 4, 5]

# List comprehension
squared_numbers = [x**2 for x in numbers]

# Using map()
squared_numbers_map = list(map(lambda x: x**2, numbers))
Enter fullscreen mode Exit fullscreen mode

To see which approach is faster,


Follow me on Dev.to for daily Python tips and quick guides!

Top comments (0)