outline-style sorting algorithm

Michael Geary Mike at DeleteThis.Geary.com
Tue Apr 20 05:51:34 EDT 2004


> Michael Geary wrote:
> > Interestingly enough, in Windows XP, Windows Explorer lists
> > these files in numerical order:
> >
> > file1
> > file2
> > ...
> > file9
> > file10
> > file11

Peter Otten wrote:
> Seems they special-cased this. Can they deal with
>
> fi1le
> fi2le
> fi10le
>
> and
>
> 1file
> 2file
> 10file
>
> too?

Yes, both Windows Explorer and 4NT sort those numerically.

It seems like a simple enough algorithm: Split each filename into groups of
numbers and non-numbers. When you do a sort comparison, take these character
groups from left to right, comparing the non-numeric parts alphabetically
and the numeric parts numerically.

-Mike





More information about the Python-list mailing list