如何将列表列表与第二个列表组合成一个列表列表?

How to combine a list of lists with a second list into a single list of lists?

我有两个相同长度的列表:

l1 = [['a','b'],['b','c'],[]]
l2 = [0,1,3]

如何从这两个列表中创建一个列表 l3 以便:

l3 = [['a','b',0],['b','c',1],[3]] 

提示:答案在这里

l1 = [['a','b'],['b','c'],[]]
l2 = [0,1,3]
l3 = [l1[i] + [x] for i, x in enumerate(l2)]

您想使用 zip:

l3 = [x + [y] for x, y in zip(l1, l2)]

Zip 创建 ('item from first list', 'item from the second list') 形式的元组列表。然后只需遍历该列表并将它们合并即可。 (上面理解的x+[y]部分。)