Sorting out sort

Mel Wilson mwilson at the-wire.com
Fri Jan 3 14:04:49 EST 2003


In article <mailman.1041604867.10805.python-list at python.org>,
Andrew Bennetts <andrew-pythonlist at puzzling.org> wrote:
>On Fri, Jan 03, 2003 at 09:29:54AM -0500, John Roth wrote:
>>
>> "Anders J. Munch" <andersjm at dancontrol.dk> wrote in message
>> news:3e144c3a$0$71645$edfadb0f at dread11.news.tele.dk...
>> > 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
t.sort()

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