如何在Python 3中将元素从列表放到列表中?

Mah*_*lam 2 python algorithm nested list python-3.x

我正在尝试将元素list2放在中的每个嵌套列表中list1。到目前为止,这是我尝试过的:

list_1 = [[0, 1], [1, 4], [2, 3]]
list_2 = [100, 100, 100]
store_1 = []
for x in list_1:
    for y in list_2:
        x.append(y)
        store_1.append(x)
print(store_1)
Run Code Online (Sandbox Code Playgroud)

但是输出是:

[[0, 1, 100, 100, 100], [0, 1, 100, 100, 100], [0, 1, 100, 100, 100], [1, 4, 100, 100, 100], [1, 4, 100, 100, 100], [1, 4, 100, 100, 100], [2, 3, 100, 100, 100], [2, 3, 100, 100, 100], [2, 3, 100, 100, 100]]
Run Code Online (Sandbox Code Playgroud)

输出应如下所示:

[[0,1,100],[1,4,100], [2,3,100]]
Run Code Online (Sandbox Code Playgroud)

如何修复我的代码以获得所需的输出?

Rak*_*esh 5

使用 zip

例如:

list_1 = [[0, 1], [1, 4], [2, 3]]
list_2 = [100, 100, 100]
store_1 = [x + [y] for x, y in zip(list_1, list_2)]
print(store_1)
Run Code Online (Sandbox Code Playgroud)

输出:

[[0, 1, 100], [1, 4, 100], [2, 3, 100]]
Run Code Online (Sandbox Code Playgroud)