Python 2.x sorted puzzlement

久未见 提交于 2019-12-06 07:50:37

It fails because the sorting algorithm depends on a total ordering of the elements, which implies transitive <.

The ordering of unicode strings, tuples, and strings isn't transitive:

>>> a = 'x'
>>> b = (1,)
>>> c = u'x'
>>> a < b
True
>>> b < c
True
>>> a < c
False

I.e., there exists no valid sort for your list. At least not with the default comparator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!