On 7/12/07, Daniel <[EMAIL PROTECTED]> wrote:
> On Fri, 13 Jul 2007 08:51:25 +0300, Gabriel Genellina
> <[EMAIL PROTECTED]> wrote:
> >> data = [row for row in csv.reader(open('some.csv', 'rb'))
> >
> > Note that every time you see [x for x in ...] with no condition, you can
> > write list(...) instead - more clear, and faster.
> >
> > data = list(csv.reader(open('some.csv', 'rb')))
>
> Clearer? Maybe, but list comprehensions are clearer (at least for me)
>
> Faster? No. List Comprehensions are faster.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

[EMAIL PROTECTED] pdfps $ python -m timeit -c 'data = list(open("make.ps"))'
100 loops, best of 3: 7.5 msec per loop
[EMAIL PROTECTED] pdfps $ python -m timeit -c 'data = [line for line in
open("make.ps")]'
100 loops, best of 3: 9.2 msec per loop

On my system just putting into a list is faster.  I think this is
because you don't need to assign each line to the variable 'line' each
time in the former case.

I, too, think it's faster to just use list() instead of 'line for line
in iterable', as it seems kind of redundant.

-- 
Kelvie
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to