I saw this in the Python documentation for zip(). Apparently, if s is [1,2,3,4,5,6,7,8,9] and n is 3, zip(*[iter(s)]*n) returns [(1,2,3),(4,5,6),(7,8,9)]. 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?
Thanks.
(This just looks so cool I gotta know.)
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.