sorting strings by size

Steve Holden sholden at holdenweb.com
Thu Aug 9 14:29:06 CEST 2001


"Mark Robinson" <m.1.robinson at herts.ac.uk> wrote in message
news:3B7266C9.90706 at herts.ac.uk...
> Can anyone thing of a more eligant way of doing this? I am trying to
> extract the keys of my dict and sort them according to size, but this
> currently seems kinda crude
>
> temp = [(len(x), x) for x in motifs.keys()]
> temp.sort()
> temp.reverse()
> motiflist = [x[1] for x in temp]
>
Well you could save yourself one of those operations:

temp = [(-len(x), x) for x in motifs.keys()]
temp.sort()
motiflist = [x[1] for x in temp]

regards
 SteVe
--
http://www.holdenweb.com/








More information about the Python-list mailing list