Re: looping versus comprehension

2013-01-31 Thread Roy Smith
In article <5109fe6b$0$11104$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 31 Jan 2013 02:49:31 +1100, Chris Angelico wrote: > > > it's worth > > noting that list appending is not going to be O(N*N), because it's going > > to allow room for expansion. > > This is true for list.a

Re: looping versus comprehension

2013-01-30 Thread Steven D'Aprano
On Thu, 31 Jan 2013 02:49:31 +1100, Chris Angelico wrote: > it's worth > noting that list appending is not going to be O(N*N), because it's going > to allow room for expansion. This is true for list.append, which is amortized constant time. But it is not true for list addition, alist + blist, wh

Re: looping versus comprehension

2013-01-30 Thread Robin Becker
On 30/01/2013 15:49, Chris Angelico wrote: On Thu, Jan 31, 2013 at 1:58 AM, Robin Becker wrote: however, when I tried an experiment in python 2.7 using the script below I find that the looping algorithms perform better. A naive loop using list += list would appear to be an O(n**2) operation, bu

Re: looping versus comprehension

2013-01-30 Thread Chris Angelico
On Thu, Jan 31, 2013 at 1:58 AM, Robin Becker wrote: > however, when I tried an experiment in python 2.7 using the script below I > find that the looping algorithms perform better. A naive loop using list += > list would appear to be an O(n**2) operation, but python seems to be doing > better than

looping versus comprehension

2013-01-30 Thread Robin Becker
An email in reportlab-us...@reportlab.com claimed that the following loop in a charting module was taking a long time I use ReportLab 2.6 but I also found the problem in ReportLab daily from 01/29/2013 in /src/reportlab/graphics/charts/lineplots.py: 276 # Iterate over data columns. 277 if se