title: replacing values in a nested tuple with the whole tuple
body: <p>Okay,</p>
  
  <p>I am working on a linguistic prover, and I have series of tuples that represent statements or expressions.
  Sometimes, I end up with an embedded "and" statement, and I am trying to "bubble" it up to the surface.
  I want to take a tuple that looks like this:</p>
  
  <pre><code>('pred', ('and', 'a', 'b'), 'x')
  </code></pre>
  
  <p>or, for a more simple example:</p>
  
  <pre><code>( ('and', 'a', 'b'), 'x')
  </code></pre>
  
  <p>and I want to separate out the ands into two statements such that the top one results in:</p>
  
  <pre><code>('and', ('pred', 'a', 'x',), ('pred', 'b', 'x') )
  </code></pre>
  
  <p>and the bottom one in:</p>
  
  <pre><code>('and', ('a', 'x'), ('b', 'x') )
  </code></pre>
  
  <p>I've tried a lot of things, but it always turns out to be quite ugly code. And I am having problems if there are more nested tuples such as:</p>
  
  <pre><code>('not', ('p', ('and', 'a', 'b'), 'x') )
  </code></pre>
  
  <p>which I want to result in </p>
  
  <pre><code>('not', ('and', ('p', 'a', 'x',), ('p', 'b', 'x') ) )
  </code></pre>
  
  <p>So basically, the problem is trying to replace a nested tuple with the value of the entire tuple, but the nested one modified. It's very ugly. :(</p>
  
  <p>I'm not super duper python fluent so it gets very convoluted with lots of for loops that I know shouldn't be there. :( 
  Any help is much appreciated!</p>