title: How to turn a list into nested dict in Python
body: <p>Need to turn x:</p>
  
  <pre><code>X = [['A', 'B', 'C'], ['A', 'B', 'D']]
  </code></pre>
  
  <p>Into Y:</p>
  
  <pre><code>Y = {'A': {'B': {'C','D'}}}
  </code></pre>
  
  <p>More specifically, I need to create a tree of folders and files from a list of absolute paths, which looks like this:</p>
  
  <pre><code>paths = ['xyz/123/file.txt', 'abc/456/otherfile.txt']
  </code></pre>
  
  <p>where, each path is <code>split("/")</code>, as per <code>['A', 'B', 'C']</code> in the pseudo example. </p>
  
  <p>As this represents files and folders, obviously, on the same level (index of the array) same name strings can't repeat. </p>