I have a class, as defined below:
def _init_(self, xcoordinate= None, ycoordinate= None, h=None, g=None, cost=None):
self.xcoordinate = xcoordinate
self.ycoordinate = ycoordinate
self.h = h
self.g = g
self.cost = h + g
return repr((self.xcoordinate, self.ycoordinate, self.h, self.g, self.cost))
I then have an array of Node objects. How do I sort this array based on the Node.cost?(the objects cost attribute).
What I have tried:
I have tried using the line below
sorted(possible_next_steps, key=lambda node: node)
but that throws an "IndexError: tuple index out of range" error. I would really appreciate your help, thanks.