David Isaac wrote:
"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Using zip(*[iter(l)]*N) or zip(*(iter(l),)*N) simply extends the above to
the
general case.
Clearly true.
But can you please go into much more detail for a newbie?
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.
See if the following interactive examples clear things up at all:
# The unclear version
Py> itr = iter(range(10))
Py> zipped = zip(*(itr,)*3) # How does this bit work?
Py> print "\n".join(map(str, zipped))
(0, 1, 2)
(3, 4, 5)
(6, 7, 8)
# Manual zip, printing as we go
Py> itr = iter(range(10))
Py> try:
... while 1: print (itr.next(), itr.next(), itr.next())
... except StopIteration:
... pass
...
(0, 1, 2)
(3, 4, 5)
(6, 7, 8)
# 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
...
Py> print "\n".join(map(str, zipped))
(0, 1, 2)
(3, 4, 5)
(6, 7, 8)
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list