[Python-Dev] Re: Re: lists v. tuples (original) (raw)
Andrew Koenig ark@research.att.com
Tue, 15 Apr 2003 17:29:24 -0400 (EDT)
- Previous message: [Python-Dev] Evil setattr hack
- Next message: [Python-Dev] Re: Re: lists v. tuples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Moreover, for some data structures, the cmp approach can be expensive. For example, if you're comparing sequences of any kind, and you know that the comparison is for == or !=, you have your answer immediately if the sequences differ in length. If you don't know what's being tested, as you wouldn't inside cmp, you may spend a lot more time to obtain a result that will be thrown away.
Guido> Yes. OTOH, as long as cmp() is in the language, these same situations Guido> are more efficiently done by a cmp implementation than by calling Guido> lt and then eq or similar (it's hard to decide which order is Guido> best). So cmp() should be removed at the same time as cmp.
Yes.
Guido> And then we should also change list.sort(), as Tim points out. Maybe Guido> we can start introducing this earlier by using keyword arguments:
Guido> list.sort(lt=function) sorts using a < implementation Guido> list.sort(cmp=function) sorts using a cmp implementation
The keyword argument might not be necessary: It is always possible for a function such as sort to figure out whether a comparison function is 2-way or 3-way (assuming it matters) by doing only one extra comparison.
- Previous message: [Python-Dev] Evil setattr hack
- Next message: [Python-Dev] Re: Re: lists v. tuples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]