Loop and the list

Holger Türk htx1 at gmx.de
Fri May 14 10:10:00 EDT 2004



Krzysztof Szynter wrote:
> def maxvalue(TY):   #gets an index of the max value in the TY list
>     max = 0
>     for i in range(0,len(TY)):
>         if (max<TY[i]):
>             max = i
>             print TY[i],max
>             continue            
>     return max

max is an index, right? So your test should be

if TY[max] < TY[i]:
     [....]

In your code, you compare the index to a value.

Greetings,

Holger




More information about the Python-list mailing list