[Tutor] how to compare elements of 2 lists

Alan Gauld alan.gauld at btinternet.com
Wed Dec 26 17:03:08 CET 2007

"Chris Fuller" <cfuller084 at thinkingplanet.net> 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 you
> have got a 2D list of known length.

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 so I agree.

But any time that you use the *[] format it is easier to
just put the content of the [] into the zip directly, which is what,
I think, Kent is saying?

>>    zip(*[a, b, ..., x, y, z])
>> can be written more simply as
>>    zip(a, b, ..., x, y, z)
>> Kent

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list