I know that this sounds trivial but I did not realize that the sort()
function of Python was weird. I have a list of \"numbers\" that are actually in string for
You can also use:
import re
def sort_human(l):
convert = lambda text: float(text) if text.isdigit() else text
alphanum = lambda key: [convert(c) for c in re.split('([-+]?[0-9]*\.?[0-9]*)', key)]
l.sort(key=alphanum)
return l
This is very similar to other stuff that you can find on the internet but also works for alphanumericals like [abc0.1, abc0.2, ...]
.