sorting a list numbers stored as strings
Amit Khemka
khemkaamit at gmail.com
Mon Sep 24 07:23:07 EDT 2007
On 9/24/07, aine_canby at yahoo.com <aine_canby at yahoo.com> wrote:
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>
Hi,
>>> l = ["1", "11", "2", "22"]
>>> sorted(l, cmp = lambda x, y: cmp(int(x), int(y))) # provide your
own compare function !
>>> l
['1', '2', '11', '22']
Cheers,
--
----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
More information about the Python-list
mailing list