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?

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Do note that Python 3.x will raise an exception when comparing different non-coercible types.
Actually I do want to raise an exception when sorting a list of differently typed objects :)
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.