Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
sort order for strings of digits
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Steven D'Aprano, post: 5058680"] Yes, but there is a lot of old code pre-dating key-based sorts. There's also some examples of code where it isn't obvious how to write it as a key-based sort, but a comparison function is simple. And people coming from other languages that only support comparison-based sorts (C?) will probably continue with what they know. Even though key-based sorting is better, there's a lot of comparison sorting that falls under "if it ain't broke, don't fix it". So even though key-based sorts are better, there are still comparison- based sorts in the wild. Python 2 has to support them. Python 3, which is allowed to break backwards compatibility, does not. So when porting to 3, you have to change the sorts. Most of the time it is simple to convert a comparison-based sort to a key- based sort. For the cases where you either can't come up with a good key function yourself, or were you want to do so mechanically, Python provides cmp_to_key. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
sort order for strings of digits
Top