Python: list.sort() query when list contains different element types

后端 未结 4 2111
清歌不尽
清歌不尽 2021-01-04 12:21

Greetings Pythonic world. Day 4 of learning Python 3.3 and I\'ve come across a strange property of list.sort.

I created a list of five elements: four st

4条回答
  •  没有蜡笔的小新
    2021-01-04 12:45

    depends on how the data needs to be sorted, but something like this can work

    l = ['a',3,4,'b']
    sorted([str(x) for x in l])
    ['3', '4', 'a', 'b']
    

提交回复
热议问题