use*_*967 0 python iterable list
是否有一种更 Pythonic 的方式(即在一行中,没有循环,也没有简单的初始化)来计算all下面的列表?
all = []
for iterable in iterables:
all.extend(iterable) # add all elements in 'iterable' to 'all'
Run Code Online (Sandbox Code Playgroud)
编辑:如果解决方案需要线性时间就可以了。我只是想要一种更易读、更短、更直接的方式。
from itertools import chain
result = list(chain(*iterables))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43 次 |
| 最近记录: |