import functoolsimport itertoolsimport numpyimport operatorimport perfplotdefforfor(a):return [item for sublist in a for item in sublist]defsum_brackets(a):returnsum(a, [])deffunctools_reduce(a):return functools.reduce(operator.concat, a)defitertools_chain(a):returnlist(itertools.chain.from_iterable(a))defnumpy_flat(a):returnlist(numpy.array(a).flat)defnumpy_concatenate(a):returnlist(numpy.concatenate(a))perfplot.show( setup=lambdan: [list(range(10))] * n, kernels=[ forfor, sum_brackets, functools_reduce, itertools_chain, numpy_flat, numpy_concatenate ], n_range=[2**k for k inrange(16)], logx=True, logy=True, xlabel='num lists' )