title: How can I link graph nodes to a dictionary whose keys are the same as the nodes?
body: <p>I'm using Networkx to build a 2d graph (for "rat in the maze" problem). I have created the graph, and when I print the Networkx graph I get the coordinates in (row, column) form. I have similarly created a separate dictionary with the same number of items in (row, column) form, so that they match the graph's node names. Now I simply need to link each dictionary key to the graph so that I can use the value of each key (where the value is the "direction" of travel that I can use). "Link" can mean either literally linking the two objects, or setting attributes of each node in the Networkx graph.</p>
  
  <p>I have tried using <code>nx.relabel_nodes()</code> and that gives me errors saying that certain keys are not in the graph when they obviously are. </p>
  
  <p>tl;dr how do I link the graph to a dictionary with the same key names?</p>
  
  <p>If there is a better way to link each node in the graph to its "direction" then please mention that as well (no need to give specific code, since I do still want to learn HOW to do it, I am just looking for direction).</p>
  
  <p>If more information is needed I'll reply with it.</p>
  
  <p>edit: </p>
  
  <p>for example, my networkx graph is declared with </p>
  
  <pre><code>row = 2
  col = 2
  mygraph = nx.grid_2d_graph(row, col)
  </code></pre>
  
  <p>When printed this returns </p>
  
  <pre><code>{(0,0), (0,1), (1,0), (1,1)} 
  </code></pre>
  
  <p>which is similar to a dictionary. Looking through NetworkX documentation I can see that using <code>relabel_node()</code> I can edit each node using a dictionary of similar structure:</p>
  
  <pre><code>mydict = {(0,0): l, (0,1): r, (1,0): u, (1,1): d} #may have mussed up the structure, but this is a dict
  </code></pre>
  
  <p>by doing </p>
  
  <pre><code>nx.relabel_nodes(mygraph, mydict, False)
  </code></pre>
  
  <p>but this returns an error saying that certain nodes are not in the graph.</p>