标签: python arrays
我试图重塑元组数组:
x = [(1,2), (5,4), (3,6)]
分成两个数组:[1,5,3]和[2,4,6]在一行
这是有效的:
a = [x[0] for x in X] b = [x[1] for x in X]
但这不起作用:
(a, b) = [(x[0], x[1]) for x in X]
如何在一行中完成?
答案 0 :(得分:0)
你可以用zip:
a, b = zip(*x)