Flattening lists

mk mrkafk at gmail.com
Thu Feb 5 11:29:41 EST 2009


Brian Allen Vanderburg II wrote:

>> Is list creation really more costly than above?
>>
> Probably not.  I wrote a small test program using a list several levels 
> deep, each list containing 5 sublists at each level and finally just a 
> list of numbers.  Flattening 1000 times took about 3.9 seconds for the 
> one creating a list at each level, and 3.2 for the one not creating the 
> list at each level.

Hmm, I'm surprised by even that! Apparently list creation is more 
expensive than I thought - it seems somewhat more expensive than the 
cost of interpreting bytecode for "if var is None". Either list creation 
is somewhat costly, or "if var is None" is really cheap.

Regards,
mk




More information about the Python-list mailing list