Help understanding the decisions *behind* python?

Piet van Oostrum piet at cs.uu.nl
Tue Jul 21 11:32:26 EDT 2009


>>>>> David Smith <dns4 at cornell.edu> (DS) wrote:

>DS> Piet van Oostrum wrote:
>>>>>>>> Hendrik van Rooyen <hendrik at microcorp.co.za> (HvR) wrote:
>>> 
>HvR> On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote:
>>>>>> On Jul 20, 6:08 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
>>>>> The main reason why you need both lists and tuples is that because a
>>>>> tuple of immutable objects is itself immutable you can use it as a
>>>>> dictionary key.
>>>>>> Really? That sounds interesting, although I can't think of any real-
>>>>>> world cases where you'd use something like that.
>>> 
>HvR> simplest is something like a point in the cartesian plane with
>HvR> an associated attribute like colour.
>>> 
>>> There are numerous other examples. Anytime you need a key that is not a
>>> single object but composed of more than one:
>>> Name + birthday
>>> Street + number + City
>>> Student + Course
>>> etc.

>DS> Compound keys (like what's listed above) can also be used for sorting
>DS> lists of dictionaries using DSU style sorting.  Something I believe (and
>DS>  I could be wrong) won't work with mutable types like lists.

For sorting there is no problem with mutable arrays as long as you don't
mutate them during the sorting process (for example in the comparison
routine). Doing that would be extremely perverse. And there is no
enforcement of that.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list