Skip to main content
 首页 » 编程设计

python之将多个列表项插入另一个列表

2025年05月04日10luoye11

<分区>

我正在尝试将一个列表中的列表项插入到另一个列表中。我找到了两个可行的解决方案,但对我来说它们似乎不必要地复杂。

我要找的基本上是这样一个列表:[1, 2, 4, 5, 3]

someList = [1, 2, 3] 
anotherList = [4, 5] 
 

第一种解决方案:

for item in anotherList: 
    someList.insert(2, item) 
 

第二种方案:

someList = someList[:2]+anotherList[:]+someList[2:] 
 

我的直觉是使用类似这样的东西,但它会插入列​​表,而不是列表项。

someList.insert(2,anotherList)