So this is what I’d “like” to be able to write:
cur_loc = min(open_set,key=lambda x:costs[x])
cur_loc is a tuple, and the goal is to set it equal to the tuple in open_set with the lowest cost. (and you find the cost of x with costs[x])
How could I do this? I tried Python.org’s documentation on min(), but I didn’t seem to find much help.
Thanks!
EDIT:
I resolved my own problem.
I was retarded and hadn’t initialized the costs dictionary. I was actually copy and pasting someone else’s python code in order to test what they were doing, but apparently the snippet they created didn’t include the initialization part. Woops. If anyone is interested:
for row in range(self.rows):
for col in range(self.cols):
myloc = (row,col)
if (myloc) not in closed_set:
costs[myloc] = (abs(end_row-row)+abs(end_col - col))*10
if (myloc) not in open_set:
open_set.add(myloc)
parents[myloc] = cur_loc
cur_loc = min(open_set,key=lambda x:costs[x])
Worked for me. What’s your question?