我有n个具有n个元素的列表,看起来像这样,在此示例中,我将仅显示一个包含2个元素的列表,但可能是n:
['-', '-']
['4.500.740', '924.372']
['1.978.095', '3.802.674']
['3.434.599', '3.614.503']
['8.588.294', '4.973.343']
我需要创建一个看起来像下一个的嵌套列表:
[['-','4.500.740','1.978.095','3.434.599','8.588.294'],['-','924.372','3.802.674','3.614.503','4.973.343']]
我一直在寻找与此相关的许多问题,但是我还不能弄清楚,所以任何建议都将不胜感激。
谢谢!
答案 0 :(得分:1)
您可以使用列表推导:
l1 = [['-', '-'],
['4.500.740', '924.372']]
l2 = [[a[n] for a in l1] for n in range(len(l1))]
print(l2)