does Python support some kind of "casting"

Peter Hansen peter at engcorp.com
Fri Mar 15 08:17:38 EST 2002


Tino Lange wrote:
> 
> > Yes, that will make a copy. But copying a list is a pretty efficient
> > operation, so no, it isn't really horribly inefficient. Have you tried it
> > and identified this as a bottleneck? How long are your lists anyway?
> 
> 3600 Elements each.
> 
> No I didn't check if it's a bottleneck. But I immediately didn't feel good
> when writing "return list(newlist)" (the list contains a list of strings 
> itself - so it's much stuff to copy)

Get over it.  3600 elements is nothing, especially once you realize that
the strings themselves are not duplicated, just the references.

Anyway, the "immediately didn't feel good" thing is probably a feeling
you'd best learn to ignore more. :-)  Only optimize when you have actually
identified a bottleneck by profiling.  And a "bottleneck" is not something 
that runs "slow", but something that runs "too slow" which means you 
also need to have a specific requirement in mind before spending your
valuable time optimizing.  Once I learned this it has made my programming
life much easier.

-Peter



More information about the Python-list mailing list