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-
I think* if you are certain the format is consistently "[0]alphabet [1]dash" following indexes beyond [2:] will always be number, then you can replace split with slice, or you can use str.index('-')
sorted(lst, key=lambda x:(int(x[2:]),x[0]))
# str.index('-')
sorted(lst, key=lambda x:(int(x[x.index('-')+1 :]),x[0]))