In data analysis we get a situation like a data is 1.1
and another like 1.1.2
where we have to sort the data
but it cannot understand the second data as a number it only looks for first number. Is there a hack to sort this data...
In data analysis we get a situation like a data is 1.1
and another like 1.1.2
where we have to sort the data
but it cannot understand the second data as a number it only looks for first number. Is there a hack to sort this data...
Use a lambda with sorted
, splitting on '.'
and mapping each section to int
.
>>> lst = ["1.1.2", "3.4.5", "1.1"]
>>> sorted(lst, key=lambda x: [int(y) for y in x.split('.')])
['1.1', '1.1.2', '3.4.5']
>>>