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="Arnaud Delobelle, post: 5058505"] You don't actually need to split the string, it's enough to return a pair consisting of the number of leading digits followed by the string as the key. Here's an implementation using takewhile: .... return sum(1 for c in takewhile(str.isdigit, s)) or 1000, s .... ['1', '1a', '9', '55', '55a', '1000', 'abc', 'abc2'] Here's why it works: [(1, '9'), (4, '1000'), (1000, 'abc2'), (2, '55'), (1, '1'), (1000, 'abc'), (2, '55a'), (1, '1a')] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
sort order for strings of digits
Top