[New-bugs-announce] [issue5855] Perhaps exponential performance of sum(listoflists, [])

sjohn report at bugs.python.org
Mon Apr 27 14:10:47 CEST 2009

New submission from sjohn <sebastianjohn at gmx.net>:

To flatten lists of lists, e.g. [[0], [1], [2], ...], I found the short
and quite python-like one-liner "sum(listoflists, [])". This, however,
has absolutely awful performance: while the equivalent way of iterating
by hand and extending a flat list is longer and uglier, it performs fast
and in linear time. The sum() variant takes unacceptably long. I do not
know why this should behave worse-than-linear...

components: Interpreter Core
files: testsumflat.py
messages: 86658
nosy: sjohn
severity: normal
status: open
title: Perhaps exponential performance of sum(listoflists, [])
type: performance
versions: Python 2.4, Python 2.5
Added file: http://bugs.python.org/file13795/testsumflat.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list