One could think Python 2 compares names alphabetically:
print(list>int) # True
print(set>list) # True
print(float<int) # True
until you try
print(dict<list) # False
Then you need to read the documentation: comparisons
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). Furthermore, some types (for example, file objects) support only a degenerate notion of comparison where any two objects of that type are unequal.
Again, such objects are ordered arbitrarily but consistently. The <
, <=
, >
and >=
operators will raise a TypeError
exception when any operand is a complex number.
(emphasis mine)
This allows your to do:
k = [ 1, "a", 'c', 2.4, {1:3}, "hallo", [1,2,3], [], 4.92, {}] # wild mix of types
k.sort() # [1, 2.4, 4.92, {}, {1: 3}, [], [1, 2, 3], 'a', 'c', 'hallo'] type-sorted
In python 3 you get
TypeError: '>' not supported between instances of ... and ...