I am very basic in python and I faced a little problem, which I can`t see the solution for that:
I have a list of class Player which has:
class player:
def __init__(self,name,wins,points):
self.name = name
self.wins = wins
self.points = points
later after making a list with data i need to sort in specific order:
- Sort in descending by
wins - If draw in
winssort descending bypoints - If draw in
pointssort ascending byname
I tried next variant of solution (which failed):
players.sort(key=lambda x: x.name)
players.sort(key=lambda x: x.points)
players.reverse()
players.sort(key=lambda x: x.wins)
players.reverse()
but after this i had a little problem with order (while wins are equal)... For example:
I have next data:
list({name:"Artur", points:20, wins:1},
{name:"Jan", points:25, wins:1},
{name:"Karol", points:10, wins:0})
after sorting I need to have next order:
Jan
Artur
Karol
but that solution that i made sorts partly wrong:
Result:
Artur
Jan
Karol
Why partly? Before final reverse it has right order:
"Karol"
"Jan" #\this group
"Artur" #/ is in right positions
So there is some solution for that? Or maybe I just "Can`t find a solution from Internet"-man?