Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2199

Re: Guido rethinking removal of cmp from sort method

References (12 earlier) <4D922B91.5030505@mrabarnett.plus.com> <AANLkTiktvGrpJM6AYP7yEYXj8heqz61ey3FuLSJG7wQH@mail.gmail.com> <AANLkTinfLaedDYKd9KeSihh5wz09fuwXN0jSV-jHQeAG@mail.gmail.com> <AANLkTinXCMTduz96su=avK4NN3PQLhgbzLi5jWA69W0g@mail.gmail.com> <4D92660B.2060307@mrabarnett.plus.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-03-29 17:36 -0600
Subject Re: Guido rethinking removal of cmp from sort method
Newsgroups comp.lang.python
Message-ID <mailman.2.1301441811.2990.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Mar 29, 2011 at 5:06 PM, MRAB <python@mrabarnett.plus.com> wrote:
> I think I've found a solution:
>
>    class NegStr:
>        def __init__(self, value):
>            self._value = value
>        def __lt__(self, other):
>            return self._value > other._value

IOW:

cmp_to_key(lambda x, y: -cmp(x, y))

This is still just taking a cmp function and dressing it up as a key.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Guido rethinking removal of cmp from sort method Ian Kelly <ian.g.kelly@gmail.com> - 2011-03-29 17:36 -0600
  Re: Guido rethinking removal of cmp from sort method Paul Rubin <no.email@nospam.invalid> - 2011-03-29 17:23 -0700

csiph-web