我有[[1,2,3], [5,6,7]]
并希望生成列表[[1,5], [2,6], [3,7]]
。我如何在Python中执行此操作?
答案 0 :(得分:0)
>>> zip([1,2,3], [4, 5, 6])
[(1, 4), (2, 5), (3, 6)]
将每个元素转换为列表
>>> [list(a) for a in zip([1, 2, 3], [4, 5, 6])]
[[1, 4], [2, 5], [3, 6]]
答案 1 :(得分:0)
result = [list(x) for x in zip([1, 2, 3], [5, 6, 7])]