gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:52 25 4
gpt4 key购买 nike

<分区>

让我们举个例子:

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 处插入的原因)。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com