相关疑难解决方法(0)

使用`sum(iterable,[])`如何使嵌套列表变平?

我正在使用python 3.6.我通过以下方式使用以下方法展平嵌套列表sum:

a = [[1, 2], [3, 4], [5, 6]]

sum(a,[])
Run Code Online (Sandbox Code Playgroud)

返回:

[1,2,3,4,5,6]
Run Code Online (Sandbox Code Playgroud)

到底发生了什么?Sum采用可迭代的,在这种情况下是一个列表,以及一个起始值.我不明白python读取什么来展平列表.

python list python-3.x

6
推荐指数
3
解决办法
231
查看次数

标签 统计

list ×1

python ×1

python-3.x ×1