- #1
ergospherical
- 1,045
- 1,335
Let a be a list (say a = [0,1,2,3,...]), then construct a list of n iterables iter(a),
When I go to unzip this, e.g.
Then x is (0,1,...,n-1), then (n,n+1,...,2n-1), etc.
Just trying to iron out why this works. Because schematically, *it is unpacking it into
*it = iter(a), iter(a), ..., iter(a)
And then zip(*it) should be joining together the first values of each of those n iterables, then the second, etc.
I assume it's because each time iter(a) is seen in zip, the iterable value is updated?
Otherwise x would be (0,0,...,0), then (1,1,...,1) etc.?
Python:
it = [iter(a)] * n
Python:
for x in zip(*it):
Just trying to iron out why this works. Because schematically, *it is unpacking it into
*it = iter(a), iter(a), ..., iter(a)
And then zip(*it) should be joining together the first values of each of those n iterables, then the second, etc.
I assume it's because each time iter(a) is seen in zip, the iterable value is updated?
Otherwise x would be (0,0,...,0), then (1,1,...,1) etc.?