Sorting out sort

Mel Wilson mwilson at
Fri Jan 3 20:04:49 CET 2003

In article <mailman.1041604867.10805.python-list at>,
Andrew Bennetts <andrew-pythonlist at> wrote:
>On Fri, Jan 03, 2003 at 09:29:54AM -0500, John Roth wrote:
>> "Anders J. Munch" <andersjm at> wrote in message
>> news:3e144c3a$0$71645$edfadb0f at
>> > What more do you need?
>> Something that chains properly.
>Really?  How often would you want to call
>l.sort().sort().reverse().reverse()?  ;)

i = s.sort().index(a)

could return the rank of the value of `a` within the
values in `s`.

   But I'm not personally comfortable with hiding that big
side effect inside an innocent-looking expression, even if
cognoscenti have learned to raise a red flag anytime they see
'.sort('.  There's already enough entry-level confusion with

t = s

and finding the values in `s` have all moved.

        Regards.        Mel.

Still, we give up the right to write

i = s[:].sort().index(a)

Oh, well.

More information about the Python-list mailing list