def sort_by_heuristic(graph, goalNode, nodes):
    """Given a list of nodes, sorts them best-to-worst based on the heuristic
    from each node to the goal node. Here, and in general for this lab, we
    consider a smaller heuristic value to be "better" because it represents a
    shorter potential path to the goal. Break ties lexicographically by 
    node name."""
    nodes.sort()
    heuristic = {}
    for node in nodes:
        heuristic[node] = graph.get_heuristic_value(node,goalNode)
    return sorted(nodes, key = lambda node:heuristic[node], reverse = False)