I have 3 lists:
>>> a = ["12", "a"]
>>> b = ["123", "b"]
>>> c = ["4", "c"]
I put them in a new list:
>>> d = [a,b,c]
When I sort them according to first item of each inner lists:
>>> sorted(d, key=itemgetter(0))
[['12', 'a'], ['123', 'b'], ['4', 'c']]
But I want:
[['4', 'c'], ['12', 'a'], ['123', 'b']]
Also, first item may have leading zero:
>>> a = ["012", "a"]
>>> b = ["0123", "b"]
>>> c = ["04", "c"]
Again, I want to see the sorted list this way:
[['04', 'c'], ['012', 'a'], ['0123', 'b']]
How can I do this?
Just use
int()in the key getter:In the second example: