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

后端 未结 4 2124
清歌不尽
清歌不尽 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:31

    This nothing uncommon. Simply sort() do not check whether list contains consistent datatypes, instead it tries to sort. So once your element is at the end, it gets analyzed lately, and so algorithm did sorted part of the list before it found an error.

    And no - it is not useful, as it heavily depends on the implemented sort mechanism.

提交回复
热议问题