Skip to main content
 首页 » 编程设计

python之将列表元素插入列表列表的 Pythonic 方法

2025年05月04日12grandyang

<分区>

让我们举个例子:

nodes = [[1, 2],[3, 4]]  
thelist = [[5, 6], [7, 8]] 

如何编写代码以便列表为:

[[1, 2],[3, 4],[5, 6],[7, 8]] 

我知道怎么做,但我想要一种优雅的 python 方式。

我的尝试:

for node in nodes: 
    thelist.insert(0, node) 

我想应该有一个更 pythonic 的方式来做到这一点。

编辑:顺序在某种程度上很重要(这就是我尝试在索引 0 处插入的原因)。