What is the precise rule used in Python in order to sort lists where the elements are lists? Can this be expressed as a 'key' or 'cmp' function? The problems comes from the fact that there are two things to consider: length and values at their position.
sorted([
[ 0, 1, 2, 3 ], # 1st line: longer list
[ 0, 1 ], # 2nd line: shorter list
[ 0, 2 ] # 3rd line: suspected last
])
Is it safe to assume that the second line will sort before the first? Is it safe to assume that the third line will sort always last?
Note, this is not about stability! The specific case above behaves that way as described. But, can the rules there be considered to be general? What are the precise rules which python applies here?
Relying on the following definition Lexicographical Order (Thanks to Ashniwi):
To compare sequences of different lengths, the shorter sequence is usually padded at the end with enough "blanks" (a special symbol that is treated as smaller than every element of A). This way of comparing sequences of different lengths is always used in dictionaries. However, in combinatorics, another convention is frequently used, whereby a shorter sequence is always smaller than a longer sequence. This variant of the lexicographical order is sometimes called shortlex order.
Is Python using 'shortlex order'. Where is proof for that assumption, beyond practical examples?