sorting strings by size

Jeffery D. Collins jcollins at boulder.net
Thu Aug 9 14:53:36 CEST 2001


def sort_by_len(x,y):
    return len(y) - len(x)

l = motifs.keys()
l.sort(sort_by_len)



On Thu, Aug 09, 2001 at 11:32:41AM +0100, Mark Robinson wrote:
> 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]
> 
> blobby

-- 
Jeffery Collins (http://www.boulder.net/~jcollins)




More information about the Python-list mailing list