shouldn't list comprehension be faster than for loops?

Carl Banks pavlovevidence at gmail.com
Fri Dec 18 13:50:00 EST 2009


On Dec 17, 9:37 am, Carlos Grohmann <carlos.grohm... at gmail.com> wrote:
> Tenting the time spent by each approach (using time.clock()), with a
> file with about 100,000 entries, I get 0.03s for the loop and 0.05s
> for the listcomp.
>
> thoughts?

You shouldn't trust your intuition in things like this.  Some features
were added to Python to make writing easier, not to make it run
faster.  This time your intuition was correct.  Next time, who knows?


Carl Banks



More information about the Python-list mailing list