[Python-Dev] Re: lists v. tuples

Alex Martelli aleax@aleax.it
Fri, 14 Mar 2003 09:03:10 +0100


On Thursday 13 March 2003 09:09 pm, Kevin J. Butler wrote:
   ...
> The important characteristics of lists are also independent of each
> other (again, IMO on the order):
>
> - mutability of length & content - used for dynamically building
> collections 
> - heterogeneity allowed but not required - used occasionally
> for specific needs

I think some methods must also go on this list of important
characteristics -- the sort method, in particular.  If you need to
sort stuff (including heterogenous stuff, EXCEPT if the latter
includes at least one complex AND at least one other number
of any kind) you put it into a list and sort the list -- that's the
Python way of sorting, and sorting is an often-needed thing.

Sorting plays with mutability by working in-place, but for many
uses it would be just as good if sorting returned a sorted copy
instead -- the key thing here is the sorting, not the mutability.


Alex