I have a class, as defined below:
class Node():
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
def _repr_(self):
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[4])
but that throws an "IndexError: tuple index out of range" error. I would really appreciate your help, thanks.