> Alan Isaac wrote:
> > I see that [iter(l)]*N produces an N element list with each element
being
> > the same iterator object, but after that
> > http://www.python.org/doc/2.3.5/lib/built-in-funcs.html
> > just didn't get me there.

"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Py> itr = iter(range(10))
> Py> zipped = zip(*(itr,)*3) # How does this bit work?
> # Manual zip, actually behaving somewhat like the real thing
> Py> itr = iter(range(10))
> Py> zipped = []
> Py> try:
> ...   while 1: zipped.append((itr.next(), itr.next(), itr.next()))
> ... except StopIteration:
> ...   pass


http://www.python.org/doc/2.3.5/lib/built-in-funcs.html says:

"This function returns a list of tuples,
  where the i-th tuple contains the i-th element from each of the argument
sequences."

So an "argument sequence" can in fact be any iterable,
and these in turn are asked *in rotation* for their yield, right?
So we pass the (identical) iterables in a tuple or list,
thereby allowing a variable number of arguments.
We unpack the argument list with '*',
which means we have provided three iterables as arguments.
And then zip works as "expected",
once we have learned to expect zip to "rotate" through the arguments.
Is that about right?

If that is right, I still cannot extract it from the doc cited above.
So where should I have looked?

Thanks,
Alan Isaac


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to