[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>)

Resources: 

https://stackoverflow.com/questions/2233204/how-does-zipitersn-work-in-python

Comments

Popular posts from this blog

[Redis] Redis Cluster vs Redis Sentinel

[Unit Testing] Test Doubles (Stubs, Mocks....etc)

[Node.js] Pending HTTP requests lead to unresponsive nodeJS