current = goal path = [] while current != start: path.append(current) current = came_from[current] path.append(start) # optional path.reverse() # optional