[Tutor] Sort pointers -
Kent Johnson
kent37 at tds.net
Fri Nov 26 14:26:26 CET 2004
Liam Clarke wrote:
> Erk, one more thing,
>
> Just playing with that Schwartzian thing, does Python automatically do
> secondary sorting?
Yes, this is normal and you can rely on it. Tuples and lists are sorted
'lexicographically' which means if the first elements are equal, they
are sorted on the second, and so on. If all existing elements are equal
but one sequence is longer, the shorter one is sorted first. Read all
about it here: http://docs.python.org/ref/comparisons.html
Kent
>
> i.e.
>
> ('p', 11), ('bb', 11), ('uu', 11)
>
> Irrelevant bits snipped. So, this is my list sorted by first element.
>
> So after the second sort -
>
> (11, ('bb', 11)), (11, ('p', 11)), (11, ('uu', 11))
>
> I notice it's already sorted them alphaetically.
>
> Is this normal, can I rely on it?
>
> Regards,
>
> Liam Clarke
>
More information about the Tutor
mailing list