[Python-Dev] Re: Re: lists v. tuples (original) (raw)
Guido van Rossum guido@python.org
Sun, 16 Mar 2003 07:32:04 -0500
- Previous message: [Python-Dev] Re: Re: lists v. tuples
- Next message: [Python-Dev] Re: Re: lists v. tuples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido> Yes. And I'm still hoping to remove cmp; there should be Guido> only one way to overload comparisons.
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.
Yes. OTOH, as long as cmp() is in the language, these same situations are more efficiently done by a cmp implementation than by calling lt and then eq or similar (it's hard to decide which order is best). So cmp() should be removed at the same time as cmp.
And then we should also change list.sort(), as Tim points out. Maybe we can start introducing this earlier by using keyword arguments:
list.sort(lt=function) sorts using a < implementation list.sort(cmp=function) sorts using a cmp implementation
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Re: Re: lists v. tuples
- Next message: [Python-Dev] Re: Re: lists v. tuples
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]