Combined natural and unnatural list sorting
Derek Basch
dbasch at yahoo.com
Tue Jun 15 20:23:47 EDT 2004
In article <mailman.27.1087343762.21521.python-list at python.org>,
tjreedy at udel.edu says...
>
> "Derek Basch" <dbasch at yahoo.com> wrote in message
> news:20040615213822.26735.qmail at web20810.mail.yahoo.com...
> > Hello All,
> >
> > I need to sort a list using an unnatural sequence.
> >
> > I have a list like so:
> >
> > foo = ["White/M", "White/L", "White/XL", "White/S", "Black/S", "Black/M"]
> >
> > print foo.sort()
> >
> > ['White/L', 'White/M', 'White/S', 'White/XL', 'Black/M', 'Black/S']
> >
> >
> > The order that I actually need is:
> >
> > ["White/S","White/M", "White/L", "White/XL", "Black/S", "Black/M"]
> >
> >
> > So, in other words, I need the colors sorted alphabetically and the the
> sizes
> > sorted logically.
>
> Last I knew, 'Black' sorts before, not after 'White' ;-) Or do you really
> want colors alphabetically?
>
> TJR
>
>
>
>
>
Your right, B comes before W. I will go back to my dunce corner now :)
Derek
More information about the Python-list
mailing list