A comprehension building 2M items is slower than the equivalent

Back to list2025-07-01
You

A comprehension building 2M items is slower than the equivalent loop. Expected?

ChatGPT

Not usually, so look at what is inside. A comprehension that calls a method per item pays the attribute lookup every time; hoisting it out (append = out.append) or using a generator when you do not need the list is what actually moves the number.