Flattening lists

Benjamin Peterson benjamin at python.org
Thu Feb 5 21:44:20 EST 2009

mk <mrkafk <at> gmail.com> writes:
> 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.

Creating a list requires several function calls on the C level (including the
dictionary lookup for the name "list") and memory allocation, which is usually
quite expensive. In contrast, the eval loop for "is None" basically uses a
pointer comparison.

More information about the Python-list mailing list