A query about list

Peter Hansen peter at engcorp.com
Fri Oct 10 08:32:48 EDT 2003


Santanu Chatterjee wrote:
> 
> Thanks for the quick reply. Yes, this is similar to what I would do
> using for loop.
> 
> But by 'simpler' what I really meant was that manipulating
> the list 'a' itself without creating a new list object.
> I read that creating new objects is time consuming (and that it is
> better to use fill a list and then 'join' to create a string, than to
> increase a string using += ). Sorry I forgot to mention it before.

Executing _any_ statement is time consuming.  The question is
how much time it consumes, though, right?  Certainly creating
a list is a fairly simple operation in Python, and I think
you should focus more on readability and functionality (making
it work) rather than worrying about performance issues right
now.  Also, modifying something in-place tends to be more 
error-prone and dangerous than building a new item from pieces
of the old (e.g. when doing multi-threaded stuff, you could
access an inconsistent view of something).  Better just to
go with the typical Python meaning of "simpler", which has
nothing to do with whether something creates new objects. :)

-Peter




More information about the Python-list mailing list