[Python] zip(*[iter(s)]*n)
zip(*[iter(s)]*n)1. A better syntax for explanation is that:
zip(*[iter(s)]*n) is same as zip(*([iter(s)] * n))2. iter() is an iterator over a sequence (in this case, s).
3. [iter(s)] * n <==> [iter(s), iter(s), ... <n times>] : creates an array of iterators
4. zip() method takes a input parameter in form of zip(*args), meaning it can take zip(x), zip(x,x), zip(x,x,x) and so forth.
5. Combining this, we are just doing:
zip(iter(s), iter(s), <repeated n times>)
Comments
Post a Comment