I am trying to figure out how to sort a list based on a certain part of each string. How do I write the key?
myKey(e)
return e[-5,-2]
print(sorted(["A: (" + str(round(7.24856, 2)) + ")", "B: (" + str(round(5.8333, 2)) + ")"], key = myKey))
I want the output to look like this: ['B: (5.83)', 'A: (7.25)']
In my full code, there are more than two strings in the list, so I cannot just sort them reversed alphabetically.
Thank you