I'm solving a search problem for which the nodes of the graph are naturally labeled by nested lists. I want to use methods (e.g. uniform cost) for which I need to associate a cost function to each node.
My instinct is to use a lookup table with the node labels (= nested lists) as keys, yielding a list of cost function values for each key. I understand why unhashable objects like lists can't be used as keys in dicts, e.g., Lookup table for unhashable in Python. But the node labels ought to be mutable - when I compute the neighbors of a node, this is done by operations on the node label.
Alternatively I could make a Node
class with a property that is the node label. However, I don't have a set of initially defined nodes - it grows during the search. So I need to keep extracting the list of node labels from the list of nodes.
Right now I am leaning toward converting the node labels back and forth from mutable to immutable types, so that I can both (1) compute a node's neighbors from its label and (2) use the node label as a dict key. But this feels dirty. Is there a better way?