How does zip(*[iter(s)]*n) work in Python?
<p>I saw this in the Python documentation for zip(). Apparently, if s is <code>[1,2,3,4,5,6,7,8,9]</code> and n is <code>3</code>, <code>zip(*[iter(s)]*n)</code> returns <code>[(1,2,3),(4,5,6),(7,8,9)]</code>. How exactly does this work? I'm not sure how the operator precedence works here. What would this look like if it was written with more verbose code?</p>

<p>Thanks.</p>

<p>(This just looks so cool I gotta know.)</p>

<p>Thanks for all the answers. I understand it fully now. The magic (or what I was not understanding) was in the iter(). Because it's the same iter(), when zip calls next() on each of the 3 iterators, it really calls next() on the same iterator, thus forwarding the iterator one at a time and giving a sequential list of groupings.</p>
