Simple: Y=zip(*X)
>>> X=[[1,2,3], [4,5,6]]
>>> Y=zip(*X)
>>> Y
[(1, 4), (2, 5), (3, 6)]
EDIT: to answer questions in the comments about what does zip(*X) mean, here is an example from python manual:
>>> range(3, 6) # normal call with separate arguments
[3, 4, 5]
>>> args = [3, 6]
>>> range(*args) # call with arguments unpacked from a list
[3, 4, 5]
So, when X
is [[1,2,3], [4,5,6]]
, zip(*X)
is zip([1,2,3], [4,5,6])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…