I would like to be able to sort a list of strings with each one containing a numerical value and a word.
lst = ["1 Make", "7 William", "35 In", "22 Collins's"]
Desired output:
["1 Make", "7 William", "22 Collins's", "35 In"]
Using sorted(lst) I get:
["1 Make", "22 Collins's", "35 In", "7 William"]
sortedcan take akeyargument, which is a function applied to the elements of the list to determine the sorted order, i.e. the elementxis sorted as if it werekey(x). Which leaves you to figure out what function to use.