[Tutor] how to compare elements of 2 lists

sith . sith618 at yahoo.com
Tue Dec 25 18:21:45 CET 2007

"sith ." <sith618 at yahoo.com> wrote:
> How can I determine if the elements in a are larger or smaller than
> the elements in b. 
>  ..
> like 2 columns in excel, the third column would be
> a new list of boolean values. Can someone help please?  Thank you.

in that case, you need to create the third column (list). Instead of
values, iterate over indices and use those to fetch the values, ie:
c = []
for i in range(min(len(a), len(b))):
  c.append(a[i] > b[i])

or using list comprehension:
c = [a[i] > b[i] for i in range(min(len(a), len(b)))]


  I finally get it.  Thank you so much.
  p.s.  Thanks Alan and Ricardo.

Never miss a thing.   Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071225/90c33a74/attachment.htm 

More information about the Tutor mailing list