Guido rethinking removal of cmp from sort method

Dan Stromberg drsalists at gmail.com
Tue Mar 29 16:32:09 EDT 2011


On Tue, Mar 29, 2011 at 12:48 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:

> On Tue, Mar 29, 2011 at 1:08 PM, Chris Angelico <rosuav at gmail.com> wrote:
> > On Wed, Mar 30, 2011 at 5:57 AM, MRAB <python at mrabarnett.plus.com>
> wrote:
> >> You would have to do more than that.
> >>
> >> For example, "" < "A", but if you "negate" both strings you get "" <
> >> "\xBE", not "" > "\xBE".
> >
> > Strings effectively have an implicit character at the end that's less
> > than any other character. Easy fix: Append a character that's greater
> > than any other. So "" < "A" becomes "\xFF" > "\xBE\xFF".
> >
> > Still not going to be particularly efficient.
>
> Not to mention that it still has bugs:
>
> "" < "\0"
> "\xff" < "\xff\xff"
> --
> http://mail.python.org/mailman/listinfo/python-list
>

It probably could be a list of tuples:

'abc' -> [ (1, chr(255 - ord('a')), (1, chr(255 - ord('b')), (1, chr(255 -
ord('c')), (0, '') ]

...where the (0, '') is an "end of string" marker, but it's getting still
slower, and quite a lot bigger, and getting so reductionistic isn't a good
thing when one class wraps another wraps another - when their comparison
methods are interrelated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110329/88837861/attachment-0001.html>


More information about the Python-list mailing list