Human sorting improved
Briefly

Effective string sorting requires treating numeric components with more nuance than simple lexicographical ordering; numbers within strings should reflect their numeric value when sorted. This article discusses an approach to convert strings like 'Python 3.9' into a sortable format using the function re.split() to segregate words and numbers, ensuring human-readable ordering. While the method provided is efficient for typical cases, those requiring more complex handling of numbers and formats might benefit from the natsort package, known for its robust features.
Sorting strings to enhance human readability often requires treating numbers numerically, which can be achieved by breaking down strings into sortable components.
The idea is to convert strings like 'Python 3.9' into a key that facilitates correct numerical sorting, allowing for human-friendly results.
There are many approaches to efficiently splitting strings into words and numbers, but this implementation remains a straightforward solution for common cases.
For more complex cases, the natsort package is recommended as it handles a wider range of sorting nuances including floats and file paths.
Read at Nedbatchelder
[
|
]