Why is this loop heavy code so slow in Python? Possible Project Euler spoilers

paulhankin paul.hankin at gmail.com
Wed Sep 19 12:59:44 EDT 2007


On Sep 2, 12:51 pm, jwrweather... at gmail.com wrote:
> ... right-angled triangle puzzle solver
>
> max = 0
> maxIndex = 0
> index = 0
> for solution in solutions:
>     if solution > max:
>         max = solution
>         maxIndex = index
>     index += 1
>
> print maxIndex

Not that it solves your slowness problem, or has anything to
do with the question you asked :), but you can replace this
last segment of your code with:

print solutions.index(max(solutions))

--
Paul Hankin




More information about the Python-list mailing list