2

From Python docs: http://docs.python.org/library/stdtypes.html#comparisons

Implementation note: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.

Is there any reason for choosing to do this over raising an exception?

saffsd
  • 23,742
  • 18
  • 63
  • 67

2 Answers2

5

About four lines up from that line you quoted:

Objects of different types, except different numeric types and different string types, never compare equal; such objects are ordered consistently but arbitrarily (so that sorting a heterogeneous array yields a consistent result).

You don't want to raise exceptions when sorting a list of differently typed objects.

Ali Afshar
  • 40,967
  • 12
  • 95
  • 109
1

It can be useful for objects of different types to be collected into a single, sorted list, in a definite order. By giving all objects a stable sort order, this behavior is default.

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304