title: Recursive traversal of a dictionary in python (graph traversal)
body: <p>I have a dictionary with the following structure:</p>
  
  <pre><code> KEY    VALUES
   v1 = {v2, v3}
   v2 = {v1}
   v3 = {v1, v5}
   v4 = {v10}
   v5 = {v3, v6}
  </code></pre>
  
  <p>The values of a key are actually links to other keys. By using the values I want to reach the other keys till the end. Some keys are not linked as you can see for <strong>v4</strong>. I think this is similar to graph traversal?</p>
  
  <hr>
  
  <p><a href="https://i.stack.imgur.com/Uup85.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uup85.png" alt="enter image description here"></a></p>
  
  <p>starting from <code>v1</code> I want to travel to all the other values:</p>
  
  <pre><code>v1 --&gt; v2 --&gt; v1
     --&gt; v3 --&gt; v1
            --&gt; v5 --&gt; v3
                   --&gt; v6      
  v4 --&gt; v10 
  </code></pre>
  
  <hr>
  
  <pre><code>def travel():
    travel_dict = defaultdict(list)
    travel_dict[v1].append(v2)
    travel_dict[v1].append(v3)
    travel_dict[v2].append(v1)
    travel_dict[v3].append(v1)
    travel_dict[v3].append(v5)
    travel_dict[v5].append(v3)
    travel_dict[v5].append(v6)
    travel_dict[v6].append(v5)
    travel_dict[v4].append(v10)
  </code></pre>
  
  <hr>
  
  <p>What Recursive function can I use to travel the dictionary?</p>