[Tutor] parsing an array
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] > a[i-1] :
When i==0 this compares a to a[-1] which is the *last* element of the
list; a > a[-1] so it prints 'greater !!'.
PS Please reply to the original post rather than starting a new thread.
More information about the Tutor