I have a class players which have their name and experience as private attributes. I have 2 functions that returns each of them.
class Player:
def __init__(self,name,experience):
self.__name=name
self.__experience=experience
def get_name(self):
return self.__name
def get_experience(self):
return self.__experience
def __str__(self):
return(self.__name + " " + str(self.__experience))
I created a game class that gets a list of players and it has a function that sorts the players based on their experience.
class Game:
def __init__(self, players_list):
self.players_list=players_list
def sort_players_based_on_exp(self):
# I don't know how to sort them
I know that the sort() method has a parameter key, but I don't know how to use that in this case.