[Tutor] parsing an array

Kent Johnson kent37 at tds.net
Thu Nov 15 16:08:38 CET 2007


sith . wrote:
> a = [[1,1],[3,1.5],[5,0]]
> for i in range(len(a)) :

This should use range(1, len(a)). You don't want i to take on the value 0.

>     if a[i][1] > a[i-1][1] :

When i==0 this compares a[0] to a[-1] which is the *last* element of the 
list; a[0][1] > a[-1][1] so it prints 'greater !!'.

Kent

PS Please reply to the original post rather than starting a new thread.


More information about the Tutor mailing list