Re: removing list comprehensions in Python 3.0



>>> import timeit
>>> t1 = timeit.Timer('list(i for i in xrange(10))')
>>> t1.timeit()
27.267753024476576
>>> t2 = timeit.Timer('[i for i in xrange(10)]')
>>> t2.timeit()
15.050426800054197
>>> t3 = timeit.Timer('list(i for i in xrange(100))')
>>> t3.timeit()
117.61078097914682
>>> t4 = timeit.Timer('[i for i in xrange(100)]')
>>> t4.timeit()
83.502424470149151

Hrm, okay, so generators are generally faster for iteration, but not
for making lists(for small sequences), so list comprehensions stay.

.



Relevant Pages

  • Re: removing list comprehensions in Python 3.0
    ... List comprehensions are faster than generator comprehensions for ... iterating over smaller sequences. ... Prev by Date: ...
    (comp.lang.python)
  • Re: increasing counter whithin loop?
    ... > the loop? ... there's nothing preventing you from doing e.g.: ... # set skip to true to skip the next iteration ... Prev by Date: ...
    (comp.lang.ruby)
  • Re: changing colors in python
    ... sequences. ... There are various other options on windows but they ... probably won't work on Linux. ... Prev by Date: ...
    (comp.lang.python)
  • Re: .NET Socket
    ... Rahul Anand wrote: ... > But later I noticed that if in last iteration the bytes come to be less than ... can call Socket.Shutdown in another thread to interrupt that blocking call. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • I dont understand what glob does here
    ... invocation, I would have seen one "file" in each iteration, not 2 ... Why does the behavior change between iterations of the foreach loop ... I've read through glob and File::Glob and I haven't seen anything ... Prev by Date: ...
    (comp.lang.perl.misc)