I wish to sort the below list first by the number, then by the text.
lst = [\'b-3\', \'a-2\', \'c-4\', \'d-2\'] # result: # [\'a-2\', \'d-2\', \'b-3\', \'c-
lst = ['b-3', 'a-2', 'c-4', 'd-2'] res = sorted(lst, key=lambda x: tuple(f(a) for f, a in zip((int, str), reversed(x.split('-'))))) print(res) ['a-2', 'd-2', 'b-3', 'c-4']