December 12, 2007

Sort In AlphaNumeric Order

Look at most sorted list of filenames, product names, or any other text that contains alphanumeric characters - both letters and numbers. Traditional sorting algorithms use ASCII comparisons to sort these items, which means the end-user sees an unfortunately ordered list that does not consider the numeric values within the strings.

For example, in a sorted list of files, "z100.html" is sorted before "z2.html". But obviously, 2 comes before 100!

Python source code included

z1.doc
z10.doc
z100.doc
z101.doc
z102.doc
Link Posted by Tim at December 12, 2007 12:03 AM | TrackBack