[Tutor] parsing an array

Aditya Lal aditya.n.lal at gmail.com
Thu Nov 15 09:01:34 CET 2007


On Nov 15, 2007 12:37 PM, sith . <sith618 at yahoo.com> wrote:

> a = [[1,2],[3,1.5],[5,6]]
> for i in a:
>     print i
>     if i[1]>i[0]:
>         print "second index is larger"
>     else:
>         print "second index is smaller"
> [1, 2]
> second index is larger
> [3, 1.5]
> second index is small
> er
> [5, 6]
> second index is larger
>
> What I'd like do is compare if 1.5 in i[1] is greater than 2 in i[0];
> for time series, t(1)>t(0) and interate through the entire list - is 6 in
> i[2]>than 1.5 in i[1] etc?
> Since the data is in columns in a text file or csv, I can't put 1.5 in the
> same sublist as 2, and 6 in the same sublist as 1.5 to make things
> easier.  What can I do?
> Thank you for your help.
>
> ------------------------------
>
>
for i in range(1,len(a)) :
  if a[i][1] > a[i-1][1] :
     print 'greater !!' # or whatever you want

-- 
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071115/0b78752d/attachment.htm 


More information about the Tutor mailing list