我有这个列表:
input = [[[1,2]], [[3,4]], [[5,6]]]
想要的输出:
output = [[1,3,5],[2,4,6]]
我试过这个:
x, y = map(list,zip(*input))
后来意识到由于多余的方括号,这种方法行不通, 有没有一种无需迭代即可解决此问题的方法。
最佳答案
你可以试试这个:
>>> from operator import itemgetter
>>> input = [[[1,2]], [[3,4]], [[5,6]]]
>>> list(zip(*map(itemgetter(0), input)))
[(1, 3, 5), (2, 4, 6)]
关于python-3.x - 有没有办法解压缩嵌套冗余列表的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63158322/