Today I will tell you about just one line of code:
zip(*[a.__iter__()]*3)
So, if you know, how it works, you can skip to the comments right now. :)
This statement may look short and simple but it's actually very interesting and, sometimes, useful Python construction. In a job interviews we ask people to tell how does it work. If a person gets along with it, well, this is a good sign.
Here is the example of what it does:
>>> a = [1,2,3,4,5,6,7,8,10]
>>> zip(*[a.__iter__()]*3)
[(1, 2, 3), (4, 5, 6), (7, 8, 10)]
Lets look at it piecemeal.
__iter__()
Returns iterator object for a list (or tuple or any other iterable object).
This method is used by the interpreter when he encounters a list in, for
example, a for
loop.
The iterator object by itself has a next()
method, which returns list items
one by one.
[]*3
Multiplication of a list creates