We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
it extracts an item from all the three iterators from the list in order. Since all the iterators are the same object, it just groups the list in chunks of 3.
Merge the Tools!
You are viewing a single comment's thread. Return to all comments →
Hi nagacharan. I will try to explain it:
❶
iter(s)
returns an iterator for S.❷
[iter(s)]*n
makes a list of n times the same iterator for s.Example: [[iter(s)]*3] = ([iter(s), iter(s), iter(s)])
ADVICE: It's not three copies of the same iterator, it's three times the same iterator object. Really:
It is equivalent to:
❹
*[]
unpack a list:Example: print(*[1,2,3,4]) = print(1,2,3,4)
❺
zip
make an iterator that aggregates elements from each of the iterables.Example:
we have:
It is equivalent to:
it extracts an item from all the three iterators from the list in order. Since all the iterators are the same object, it just groups the list in chunks of 3.
Example:
Output:
(a,b,c)
(d,e,f)
(g,h,i)