python sort by string number code example
Example 1: python sort list of strings numerically
# Example usage:
your_list = ['cmd1','cmd10', 'cmd111', 'cmd50', 'cmd99']
your_list.sort(key=lambda x: int(x[3:]))
print(your_list)
--> ['cmd1', 'cmd10', 'cmd50', 'cmd99', 'cmd111']
Example 2: sort strings as numbers python
>>> b = ["949.0","1099.0"]
>>> b.sort(key=float)
>>> b
['949.0', '1099.0']
Example 3: sort strings as numbers python
a = sorted(a, key=lambda x: float(x))