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="Ian Kelly, post: 5058399"] In the example you have given they already seem to be split, so you could just do: sorted(n, key=int) + sorted(s) If that's not really the case, then you could construct (str, int) tuples as sort keys: sorted(n+s, key=lambda x: ('', int(x)) if x.isdigit() else (x, -1)) Note that the empty string sorts before all numbers here, which may or may not be desirable. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
sort order for strings of digits
Top