Guido rethinking removal of cmp from sort method

Antoon Pardon Antoon.Pardon at rece.vub.ac.be
Thu Mar 24 05:23:23 EDT 2011


On Wed, Mar 23, 2011 at 10:40:11AM -0600, Ian Kelly wrote:
> On Wed, Mar 23, 2011 at 9:14 AM, Antoon Pardon
> <Antoon.Pardon at rece.vub.ac.be> wrote:
> > Which isn't helpfull if where you decide how they have to be sorted is
> > not the place where they are actually sorted.
> >
> > I have a class that is a priority queue. Elements are added at random but
> > are removed highest priority first. The priority queue can have a key or
> > a cmp function for deciding which item is the highest priority. It
> > can also take a list as an initializor, which will then be sorted.
> >
> > So this list is sorted within the class but how it is sorted is decided
> > outside the class. So I can't do the sort in multiple steps.
> 
> You can't do this?
> 
> for (key, reversed) in self.get_multiple_sort_keys():
>     self.pq.sort(key=key, reversed=reversed)

Sure I can do that. I can do lots of things like writing a CMP class
that I will use as a key and where I can implement the logic for
comparing the original objects, which I otherwise would have put in a
cmp function. I thought this wasn't about how one can get by without
the cmp argument. This was about cases where the cmp argument was the
more beautiful or natural way to handle this case.

I think I have provided such a case. If you don't agree then
don't just give examples of what I can do, argue how your solution
would be a less ugly or more natural way to handle this.



More information about the Python-list mailing list