Human sorting improved

· Ned Batchelder · March 29, 2025, 5:12 p.m.
Summary
The post discusses an improved method of human-friendly sorting for strings in Python, addressing the issue where numeric strings are not sorted in a numerically logical manner. The author introduces a function that creates a sort key that correctly orders items like 'Python 3.9', making it easily understandable to human readers. Key improvements include case insensitivity and the use of tuples to differentiate between similar looking strings. While there are limitations discussed, the author highlights the utility of this approach, particularly for developers dealing with similar sorting challenges.
AUTHOR
Sponsored
Zulip logo Zulip
Organized team chat for people who take work seriously. Topic-based threading keeps conversations focused.
Try Zulip
Become a sponsor →