Combined natural and unnatural list sorting

Derek Basch dbasch at yahoo.com
Thu Jun 17 04:42:32 CEST 2004


In article <caqhs6$4h9$03$1 at news.t-online.com>, __peter__ at web.de says...
> Derek Basch wrote:
> 
> > I have a list like so:
> > 
> > foo = ["White/M", "White/L", "White/XL", "White/S", "Black/S", "Black/M"]
> 
> > The order that I actually need is:
> > 
> > ["White/S","White/M", "White/L", "White/XL", "Black/S", "Black/M"]
> 
> > I looked for a while at using comparison functions with sort but I don't
> > think that will work. Anyone been down this road? Suggestions?
> 
> Here's a slightly more complicated approach. Turn what was the "unnatural"
> into the "natural" order:
> 
> from itertools import count
> 
> class Size(object):
>     all = {}
>     _nextIndex = count().next

Wow! Thanks for sharing the knowledge everyone. I think I am starting to 
get my head around these sorting idioms. It will take me a bit to study 
all the code you sent.  Every day the forums remind me what a noob I am 
;) 



More information about the Python-list mailing list