Hacker News new | ask | show | jobs
by snissn 3752 days ago
Adding to this, I've found from profiling a lot of Python 2.7 code that a lot of those little cute one liner list comprehension expressions are slower than the expanded for loop forms. And also the expanded loops are a lot easier to change after the fact, for example if you want to do two operations on an item in your loop, you then have to expand it out anyway.
1 comments

Did you try generator expressions as well? I'd hope that the interpreter would manage to make them as fast as the loop form, but...