*expression
applies argument unpacking to the function call. It takes the expression
part, which has to resolve to a iterable, and makes each element in that iterable a separate parameter to the function.
So, zip(x, y)
returns an iterator (which is an iterable), and each element in that iterator is made an argument to the outer zip()
function.
For zip(*[(i*10, i*12) for i in xrange(4)])
it is perhaps a little clearer; there are several elements here:
[(i*10, i*12) for i in xrange(4)]
(should berange()
in python 3) creates a list with 4 tuples,[(0, 0), (10, 12), (20, 24), (30, 36)]
- The
zip(*...)
part then takes each of those 4 tuples and passes those as arguments to thezip()
function. zip()
takes each tuple and pairs their elements; two elements per tuple means the result is 2 lists of 4 values each.
Because the zip()
function produces two sequences, they can be assigned to the two variables.
I would have found the following a far more readable version of the same expression:
rr, tt = tuple(range(0, 40, 10)), tuple(range(0, 48, 12))