no more comparisons

Dan Bishop danb_83 at yahoo.com
Wed Mar 12 21:55:08 EDT 2008


On Mar 12, 6:52 pm, Alan Isaac <ais... at american.edu> wrote:
> Paul Rubin wrote:
> > The cmp option should not be removed.  However, requiring
> > it to be specified as a keyword parameter instead of just
> > passed as an unlabelled arg is fine.
>
> Sure; I would have no problem with that.
>
> But that is not what is happening.
>
> As for Carl's suggestion to use ``key``:
> this is already possible when it is convenient,
> but it is not always convenient.  (Even aside
> from memory considerations.)

def cmp_key(cmp_fn):
    class CmpWrapper(object):
        def __init__(self, obj):
            self.obj = obj
        def __cmp__(self, other):
            return cmp_fn(self.obj, other.obj)
    return CmpWrapper



More information about the Python-list mailing list