sorting a list numbers stored as strings

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Sep 24 07:23:03 EDT 2007


aine_canby at yahoo.com a écrit :
> hi,
> 
> I have the following list -
> 
> ["1", "11", "2", "22"]
> 
> how do I sort it like this -
> 
> ["1", "2", "11", "22"]

source = ["1", "11", "2", "22"]
result = [t[1] for t in sorted((int(item), item) for item in source)]
print result




More information about the Python-list mailing list