dicts are not orderable in python 3?
问题 Why are dicts orderable in python2, but not in python3? I can't find it anywhere in the documentation. Python 3.3.4 (default, Feb 11 2014, 16:14:21) >>> sorted([{'a':'a'},{'b':'b'}]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: dict() < dict() vs. Python 2.7.6 (default, Feb 26 2014, 12:01:28) >>> sorted([{'a':'a'},{'b':'b'}]) [{'a': 'a'}, {'b': 'b'} 回答1: Python 2 uses an undocumented ordering, implemented as a .__cmp__() special method.