[Tutor] how to compare elements of 2 lists

tezlo tezlo at gmx.net
Tue Dec 25 17:05:58 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)))]


More information about the Tutor mailing list