[Tutor] how to compare elements of 2 lists

Alan Gauld alan.gauld at btinternet.com
Tue Dec 25 17:38:23 CET 2007


"sith ." <sith618 at yahoo.com> wrote

> I'd like
> 4 to 8,
> 3 to 6,
> 2 to 3 and so on; like 2 columns in excel, the third column would be 
> a new list of boolean values.

results = [ A[n] == B[n] for n in len(A) ]

You should check that A and B are equal lengths of course...

You could also substitute cmp(A,B) which will return -1,0,1 depending 
on
whether A<B; A==B; A>B respectively


HTH,

Alan G




More information about the Tutor mailing list