[Tutor] list comprehension problem
alan.gauld at btinternet.com
Sat Jul 4 01:17:43 CEST 2009
"Dinesh B Vadhia" <dineshbvadhia at hotmail.com> wrote
> As the lists of integers get larger ... the list comprehension
> solution will get slower. Do you agree?
Yes thats why Chris said the linear loop solution is almost
certainly faster in this case. However you could speed up
the for loop significantly by missing out the call to
>>> for x in d:
>>> y += x
Should give the same result...
List Comprehensions are not always the best answer.
Author of the Learn to Program web site
More information about the Tutor