Having trouble understanding Python behavior when using inequality operators to compare lists. Here's a snippet using the python3 command line interpreter:
>>> [8] < [7]
False
>>> [8] < [9]
True
>>> [8, 6] < [9]
True
>>> [8, 6] < [9, 7]
True # So far so good
>>> [8, 6] < [9, 5]
True # Huh?
So, clearly Python isn't just moving through parallel indexes. I did find some information which says that in this scenario, Python orders the lists "lexicographically", which I guess means alphabetically.
So, I thought maybe the lists get sorted and then compared by parallel, but this is disproven by the following example:
>>> [1, 2, 3] < [3, 2, 1]
True
My guess was that the internal comparison would be [1, 2, 3] < [1, 2, 3], which should have returned False, since 1 < 1 is False, 2 < 2 is False, etc..
Any help is appreciated.
It actually makes a lot of sense.
The comparison is done similar as you would sort words, in lexicographical order. After all, words are also lists: lists of characters.
You first consider the first item. If one is smaller, the whole sequence is smaller, if they are equal, you move to the second item, etc.
Clearly, "86" comes before "95", just as "az" comes before "bc" and "100" comes before "90".
More here.