Combined natural and unnatural list sorting
Terry Reedy
tjreedy at udel.edu
Tue Jun 15 23:43:17 EDT 2004
"Derek Basch" <dbasch at yahoo.com> wrote in message
news:MPG.1b39345fc40c505e989680 at news-server.san.rr.com...
> 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...
> > > 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']
> > Last I knew, 'Black' sorts before, not after 'White' ;-)
> Your right, B comes before W. I will go back to my dunce corner now :)
Better to learn the lesson I and others have learned the hard way: either
label posted code untested or test it and copy and paste both the code and
the actual output.
>>Or do you really want colors [non]alphabetically?
Once you use a custom sort order for the sizes, adding a 'logical' color
order like White, Yellow, Orange, Red, Green, Blue, Purple, Black would not
be too much extra work.
Terry J. Reedy
More information about the Python-list
mailing list