Re: [Tutor] how to compare elements of 2 lists

2008-01-04 Thread Remco Gerlich
Hi, a = [4,3,2,6,7,9] b = [8,6,3,3,2,7] You can turn this into a list of two element tuples with zip(): >>> zip(a,b) [ (4,8),(3,6,),(2,3),(6,3),(7,2),(9,7) ] Now you can loop through that and compare both elements, for instance I believe this list comprehension is what you're looking for: [ t[0

Re: [Tutor] how to compare elements of 2 lists

2007-12-26 Thread Chris Fuller
On Wednesday 26 December 2007 10:03, Alan Gauld wrote: > I thought I was following this but now I'm not sure. > > Do you mean that if I have a list L that contains an arbitrary > > number of sublists that I can call zip using: > >>> zip(*L) > > rather than > > >>> zip(L[0],L[1],, L[n]) > > If s

Re: [Tutor] how to compare elements of 2 lists

2007-12-26 Thread Alan Gauld
"Chris Fuller" <[EMAIL PROTECTED]> wrote > "Arbitrary" means any size, and particularly, an unknown size. If > you don't > know how big the list is when you are writing the code, you need to > use this > syntax. > > It's also more concise and less error prone than zip(l[0], l[1], > l[2]) if yo

Re: [Tutor] how to compare elements of 2 lists

2007-12-26 Thread Chris Fuller
"Arbitrary" means any size, and particularly, an unknown size. If you don't know how big the list is when you are writing the code, you need to use this syntax. It's also more concise and less error prone than zip(l[0], l[1], l[2]) if you have got a 2D list of known length. On Wednesday 26 D

Re: [Tutor] how to compare elements of 2 lists

2007-12-26 Thread Kent Johnson
Chris Fuller wrote: > I didn't think of that. But for an arbitrary 2D list, you need the asterisk > syntax. I don't know what you mean by "an arbitrary 2D list". You need the * syntax when your arguments are *already* in a list. For any number of arguments, zip(*[a, b, ..., x, y, z]) can be

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Chris Fuller
I didn't think of that. But for an arbitrary 2D list, you need the asterisk syntax. On Tuesday 25 December 2007 19:00, you wrote: > Chris Fuller wrote: > zip(*[a,b]) > > > > [(4, 8), (3, 6), (2, 3), (6, 3), (7, 2), (9, 7)] > > This can be just zip(a, b) > > Kent ___

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Kent Johnson
Chris Fuller wrote: zip(*[a,b]) > [(4, 8), (3, 6), (2, 3), (6, 3), (7, 2), (9, 7)] This can be just zip(a, b) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Chris Fuller
The most concise way to do this is to transpose the list (convert a axb array to bxa), then complare the elements that are pairs of one value each of the original lists. You have two lists, a and b.  Put these into a list and you have a 2x6 2d "array". >>> [a,b] [[4, 3, 2, 6, 7, 9], [8, 6, 3, 3

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Ricardo Aráoz
sith . wrote: > sith . wrote: >> Hi, >> I've read the posts on comparing 2 lists and couldn't find the answer to >> my question. >> I have 2 lists >> a = [4,3,2,6,7,9] >> b = [8,6,3,3,2,7] >> How can I determine if the elements in a are larger or smaller than the >> elements in b. >> >> for i in a

[Tutor] how to compare elements of 2 lists

2007-12-25 Thread sith .
"sith ." 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. Hi, in that case, you need to create the third column (list).

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Alan Gauld
"sith ." <[EMAIL PROTECTED]> 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 subst

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread tezlo
"sith ." <[EMAIL PROTECTED]> 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. Hi, in that case, you need to create the t

[Tutor] how to compare elements of 2 lists

2007-12-25 Thread sith .
sith . wrote: > Hi, > I've read the posts on comparing 2 lists and couldn't find the answer to > my question. > I have 2 lists > a = [4,3,2,6,7,9] > b = [8,6,3,3,2,7] > How can I determine if the elements in a are larger or smaller than the > elements in b. > > for i in a: > for u in b: >

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Ricardo Aráoz
sith . wrote: > Hi, > I've read the posts on comparing 2 lists and couldn't find the answer to > my question. > I have 2 lists > a = [4,3,2,6,7,9] > b = [8,6,3,3,2,7] > How can I determine if the elements in a are larger or smaller than the > elements in b. > > for i in a: > for u in b: >

[Tutor] how to compare elements of 2 lists

2007-12-25 Thread sith .
Hi, I've read the posts on comparing 2 lists and couldn't find the answer to my question. I have 2 lists a = [4,3,2,6,7,9] b = [8,6,3,3,2,7] How can I determine if the elements in a are larger or smaller than the elements in b. for i in a: for u in b: i > u does not retu