A Python 3 learner here:
The question had the following accepted answer:
rr,tt = zip(*[(i*10, i*12) for i in xrange(4)])
which returns two tuples. I'd be grateful if someone could break down the answer and explain what it is doing with Python 3 in mind ( I know the range()
returns an iterator in Python 3). I understand list comprehensions but I'm confused about unpacking (I thought you could only used a starred expression as part of an assignment target).
I'm equally confused by the code below. I understand the outcome and zipping (or think I do) but again the asterisk expression has got me beat.
x2, y2 = zip(*zip(x, y))
from this:
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zip(x, y))
>>> x == list(x2) and y == list(y2)
True