There are some subtle and crucial concepts that I meet again and again. The problem is that once I’m done with them sometimes I tend to forget some of them. Sorting string variables in a humane (alphabetical, natural) instead of ASCIIbetical order is just one of those concepts. I had to re-discover this issue as I was trying to write a file renaming program in Python today. My problem can be described as
>>> "u11-Phrase 099.wav" >> "u11-Phrase 100.wav" >> "u11-Phrase 101.wav" < "u11-Phrase 1000.wav" False
So according Python (or your favorite language’s default sort functionality!) “u11-Phrase 100.wav” comes before “u11-Phrase 1000.wav” but “u11-Phrase 101.wav” comes after “u11-Phrase 1000.wav”!
For solutions please see one of those:
- Python sorts ?u11-Phrase 1000.wav? before ?u11-Phrase 101.wav?; how can I overcome this?
- Human sorting
- Sorting for Humans : Natural Sort Order