[Tutor] how to compare elements of 2 lists

Chris Fuller cfuller084 at thinkingplanet.net
Wed Dec 26 16:30:21 CET 2007


"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 December 2007 08:51, you wrote:
> 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 written more simple as
>    zip(a, b, ..., x, y, z)
>
> Kent
>
> > 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


More information about the Tutor mailing list