有没有办法在 Python 中没有 for 循环的情况下将可迭代对象中的所有元素添加到列表中?

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)

编辑:如果解决方案需要线性时间就可以了。我只是想要一种更易读、更短、更直接的方式。

War*_*ser 5

from itertools import chain

result = list(chain(*iterables))
Run Code Online (Sandbox Code Playgroud)