Python bogs down where there is excess use of the dynamic aspects, e.g., a large list comprehension.
Go with a generator, and watch that list be more kind to the resources.
Go with a generator, and watch that list be more kind to the resources.
This is a micro-optimization and it's not always true. Generators usually use less memory, but list comprehensions can actually be faster because the memory gets allocated all at once and the loop is performed internally inside the interpreter, instead of the generator possibly being consumed as a slow top-level loop.
I was talking about examples like making a copy of a list/dict/object instead of replacing elements in-place, or using a stack of map/filter operations instead of a single-pass for-loop with dynamic programming.