title: Convert a nested dataset to a flat dataset, while retaining enough data to convert it back to nested set
body: <p>Say I have a dataset like</p>
  
  <pre><code>(1, 2, (3, 4), (5, 6), (7, 8, (9, 0)))
  </code></pre>
  
  <p>I want to convert it to a (semi) flat representation like,</p>
  
  <pre><code>(
  (1, 2),
  (1, 2, 3, 4),
  (1, 2, 5, 6),
  (1, 2, 7, 8),
  (1, 2, 7, 8, 9, 0),
  )
  </code></pre>
  
  <p>If you use this, (taken from SO)</p>
  
  <pre><code>def flatten(iterable):
      for i, item in enumerate(iterable):
          if hasattr(item, '__iter__'):
              for nested in flatten(item):
                  yield nested
          else:
              yield item
  </code></pre>
  
  <p>this will convert it to a list like(after iterating)</p>
  
  <pre><code>[1, 2, 3, 4, 5, 6, 7, 8, 9]
  </code></pre>
  
  <p>But I cant get the original from this reperenstation, while I can get the original back from the first. (If every tuple has 2 elements only)</p>