I need to sort this list of instances using the third value which represents the XP. My function creates an instance of the CodeFighter class using CodeFighter(*codefighter) and I'm not sure how I can sort this without returning a value??
These are the values I'm using to create the instances:
[["Warrior", "1", "1050"], ["Ninja!", "21", "995"], ["Recruit", "3", "995"]]
def sortCodefighters(codefighters):
res = [CodeFighter(*codefighter) for codefighter in codefighters]
res.sort(reverse=True)
return list(map(str, res))
class CodeFighter:
def __init__(self,name,id,xp):
self.name=name
self.id=int(id)
self.xp =int(xp)
??????
__lt__()operator.