flatten a list of list

Chris Rebert clp2 at rebertia.com
Sun Aug 16 07:43:00 EDT 2009


On Sun, Aug 16, 2009 at 7:31 AM, Steven
D'Aprano<steve at remove-this-cybersource.com.au> wrote:
> On Sun, 16 Aug 2009 06:59:52 -0400, Chris Rebert wrote:
>>> Surely that's going to be O(N**2)?
>>
>> The OP asked for "simple", not "best", "most proper", or "fastest". My
>> comment was intended to mean that the code was marginally *simpler*, not
>> faster.
>
> Fair enough, but he also asked for Pythonic, and while some people might
> argue that "terrible performance" is Pythonic, I hope you wouldn't be one
> of them! :)

Indeed not. :) I expected it would be worse performance-wise than the
OP's original due to all the intermediate lists that get produced; it
shouldn't be used in optimized production code.

> If it soothes your ruffled sense of honour *wink*, I think your solution
> with itertools.chain is probably the best so far.

Except it's not really my solution, it's whoever put it in the
itertools docs's. :(
But I'm glad to been able to help by pointing the recipe out. :-)

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list