This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I have a list of strings which include numbers that I would like sorted alphanumerically, i.e. ["Foo100", "Foo2", "Foo1"] should be sorted to ["Foo1", "Foo2", "Foo100"]. A number of suggestions on Google suggest splitting the string at some known point, but my strings are an awkward bunch that would require several custom string splitting methods. Is there an existing method (or one line bit of Python magic) that will come out with the expected answer for an arbitrary set of strings, or do I need to go forth and do some coding?
A subset of the data would be:
["55 Cnc", "CoRoT-01", "CoRoT-02", "CoRoT-11", "GJ 436", "GJ 3470", "HAT-P-01", "HAT-P-11", "HAT-P-46", "HD 17156", "HD 80606", "HD 149026", "HD 189733", "K2-03", "K2-19", "Kepler-8", "Kepler-13", "Kepler-68", "Kepler-89", "Kepler-419", "WASP-10", "WASP-11", "WASP-103"]
This is the order I would expect them to be sorted into, the original order being fairly random.
Edit: The term for the sort I wanted was natural sort, and plugging that into Google gives plenty of suggestions (mostly including re and natsort as mentioned by the comments below).
Subreddit
Post Details
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...