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 1000.wav"
True
>>> "u11-Phrase 100.wav" < "u11-Phrase 1000.wav"
True
>>> "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
Benzer Yazılar / Similar Posts:
- Emotional Content of True and False Memories
- Basit bir problem üstüne çeşitlemeler – Variations on a theme
- Natural language watermarking via morphosyntactic alterations
- Design Pattern mi yoksa Implementation Pattern mi?
- Readability tests and metrics
- Reasoning over Semantic Networks
- Natural Language Toolkit (NLTK) and Google App Engine
- Echo Nest Goodness API for Music Analysis and Recommendation
- Greenspun’s 10. Rule and Conway’s Interview on Perl 6
- IronPython Videosu ve .NET’in Geleceği
Tags: python
This entry was posted
on Monday, December 21st, 2009 at 5:30 pm and is filed under General, Programlama.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
2 comments so far
Leave a reply