What is the best way to sort a list of strings with trailing digits
>>> list = ['mba23m23', 'mba23m124', 'mba23m1', 'mba23m5']
>>> list.sort()
>>> print list
['mba23m1', 'mba23m124', 'mba23m23', 'mba23m5']
is there a way to have them sorted as
['mba23m1', 'mba23m5', 'mba23m23', 'mba23m124']
sort(key=lambda s:int(s[6:]))works as long as the prefix is always 6 characters. Otherwise useitertools.groupbyor a regex to separate the numbers from the non-numbers.