In Python 3, the method list.sort()will perform a lexicographic look. But in Python 3, comparing a list with floator intcalls a TypeError, unlike Python 2, where you can do this:
>>> [0, 1] < 2
False
What is the best way to achieve old Python 2 behavior?
I tried subclassing list, but for this, each of the nested lists must be added to the type of the subclass so that all nested comparisons use overridden comparison methods. Is there a way to accomplish this that doesn't resort to recursively converting all nested lists to a subclass?
I would like to compare two lists:
>>> a = [[[0, 1], [2, 3]], [0, 1]]
>>> b = [[0, 1], [2, 3]]
>>> a < b
False
False, a[0][0] list, b[0][0] int, int , a list.
Edit:
, Python 3 list.sort, , list float int, list .