(Jan-25-2022, 06:23 PM)deanhystad Wrote:x = ['Finley : 10', 'Evie : 0', 'P1 : 0', 'P2 : 5', 'P1 : 0', 'P2 : 5', 'Finley : 15', 'Evie : 5'] x.sort(key=lambda x: int(x.split(":")[1])) print(x)Could also use the name for when the score is the same.
Output:['Evie : 0', 'P1 : 0', 'P1 : 0', 'P2 : 5', 'P2 : 5', 'Evie : 5', 'Finley : 10', 'Finley : 15']
x = ['Finley : 10', 'Evie : 0', 'P1 : 0', 'P2 : 5', 'P1 : 0', 'P2 : 5', 'Finley : 15', 'Evie : 5'] x.sort(key=lambda x: (int(x.split(":")[1]), x)) print(x)
Output:['Evie : 0', 'P1 : 0', 'P1 : 0', 'Evie : 5', 'P2 : 5', 'P2 : 5', 'Finley : 10', 'Finley : 15']
Hello dean,
I tried a different approach but cant get to your result. How come?
dt = {'Finley' : 10, 'Evie' : 0, 'P1' : 0, 'P2' : 5, 'P1' : 0, 'P2' : 5, 'Finley' : 15, 'Evie' : 5} sorted_dt_value = sorted(dt.values()) print(sorted_dt_value)
Output:[0, 5, 5, 15]
To be more precise it seem to be a list but x is a dictionnary. Used split to get rid of the comma.