How to sort a list of strings numerically?

前端 未结 14 2538
你的背包
你的背包 2020-11-22 03:43

I know that this sounds trivial but I did not realize that the sort() function of Python was weird. I have a list of \"numbers\" that are actually in string for

14条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 04:04

    Seamus Campbell's answer doesnot work on python2.x.
    list1 = sorted(list1, key=lambda e: int(e)) using lambda function works well.

提交回复
热议问题