there is list
a = ["100", "2", "33", "-10"]
when I apply sort like this
sorted(a)
It gets
['-10', '100', '2', '33']
My question is how it sort numbers in string format?
I don't need any code which convert string to integers.
there is list
a = ["100", "2", "33", "-10"]
when I apply sort like this
sorted(a)
It gets
['-10', '100', '2', '33']
My question is how it sort numbers in string format?
I don't need any code which convert string to integers.
It sorts by the first character of them, so 100
's first character is 1
so it is gonna be before 33
and 2
. Whereas the reason why -10
is before 100
is because in the python character order -
is before the numbers:
>>> ord('-')
45
>>> ord('1')
49
>>>