I am trying to sort list of strings containing numbers
a = ["1099.0","9049.0"]
a.sort()
a
['1099.0', '9049.0']
b = ["949.0","1099.0"]
b.sort()
b
['1099.0', '949.0']
a
['1099.0', '9049.0']
But list b is sorting and not list a
use a lambda inside sort to convert them to float and then sort properly:
a = sorted(a, key=lambda x: float(x))
so you will mantain them as strings but sorted by value and not lexicographically
ais already sorted.1is smaller that9. - Felix Kling0always and smaller number at index0- Vaibhav Jain