title: Transitive reduction - Error with code - Python
body: <p>So I am trying to write a code to do transitive reduction of Acyclic graph. 
  So the elements are: </p>
  
  <blockquote>
    <p>(3, 5), (5, 2), (2, 1), (4, 2), (3, 1), (4, 1)</p>
  </blockquote>
  
  <p>This is what I have written so far: </p>
  
  <pre><code>graph = [[3, 5],[5, 2],[2, 1],[4, 2],[3, 1],[4, 1]]
  
  for i in range(len(graph)):
      for j in range(len(graph)):
          for k in range(len(graph)):
              if [i,j] in graph and [j,k] in graph:
                  a = [i,k]
                  graph.pop(a)
  print(graph)                
  </code></pre>
  
  <p>After running I am expecting to get the following with (4,1) removed:</p>
  
  <pre><code>&gt;&gt; (3, 5), (5, 2), (2, 1), (4, 2), (3, 1)
  </code></pre>
  
  <p>But instead it returns:</p>
  
  <pre><code>&gt;&gt; (3, 5), (5, 2), (2, 1), (4, 2), (3, 1), (4, 1)
  </code></pre>
  
  <p>I cant figure out what I am doing wrong. If someone can point out the error, it would be great!</p>
  
  <p>P.S: Transtive reduction is removing the redundant edges of a graph. For example:</p>
  
  <p>if ( A -> B ) and ( B -> C ), then ( A -> C ), in other words: if A is connected to B and B is connected to C, then A is also connected to C. And in this case 
  ( A -> C ) is redundant because A can reach C through B therefore should be removed.</p>