title: Finding equal values from a list of list of tuples in Python
body: <p>After searching a lot without success I need help.</p>
  
  <p>I have a list of list of tuples. Each list inside the list of list represent certain numbers of formulas in my system. Any element in this list is a tuple that represent the type of the element (variable, parameter, constant, an operation...) and  the name of the element. For example for the formulas <strong>x1+x2+A1</strong>, <strong>x1-x3</strong> and <strong>sin(x2)+A1</strong> we'll have:</p>
  
  <pre><code>[
  [('VAR', 'x1'), ('PLUS', '+'), ('VAR', 'x2'), ('PLUS', '+'), ('PAR', 'A1')],
  [('VAR', 'x1'), ('LESS', '-'), ('VAR', 'x3')],
  [('SIN', 'sin'), ('VAR', 'x2'), ('PLUS', '+'), ('PAR', 'A1')]
  ]
  </code></pre>
  
  <p>I'm trying to determine in which formula each variable appear. In the example above I have that x1 variable is on 1 and 2 formula, x2 variable is on 1 and 3 formula and x3 in 2 formula, so my output will be something like:</p>
  
  <pre><code>[
  ['x1', 1, 2],
  ['x2', 1, 3],
  ['x3', 2],
  ]
  </code></pre>
  
  <p>At the moment I have very inefficient code that doesn't work at all, but here it is:</p>
  
  <pre><code>cont = 0
  for subL1 in L:
      for subL2 in L:
          if len(subL1) != 1 and len(subL2) != 1:
              if subL1 != subL2 and subL2:
                  for x,y in subL1:
                      for z,t in subL2:
                          if (    x == 'VAR'
                              and z == 'VAR'
                              and y == t
                              ):
                              print "Variable", y , "repeated"
          else:
              print "list with 1 lenght\n"
      subL1.pop(0)
  cont = cont + 1
  </code></pre>