question on list comprehensions

Roberto Antonio Ferreira De Almeida roberto at
Thu Oct 14 17:02:52 CEST 2004

Darren Dale wrote:
> Hi,
> I need to replace the following loop with a list comprehension:
> res=[0]
> for i in arange(10000):
>  res[0]=res[0]+i

res[0] = (10000 * (10000-1))/2.0   ;-)

> In practice, res is a complex 2D numarray. For this reason, the regular
> output of a list comprehension will not work: constructing a list of every
> intermediate result will result in huge hits in speed and memory.

Why do you *need* to replace the for loop with a listcomp? Could you 
give more details about what you're doing with the complex array?


More information about the Python-list mailing list