title: How to create a nested dictionary for storing directory structure in python?
body: <p>Suppose the following <strong>directory structure</strong>: -</p>
  <pre><code>|--apc
  |   |--data
  |   |   |--datainstaller.zip
  |   |   |--rs_details
  |   |   |   |--readme.txt
  |   |--rem
  |   |   |--15.0.x
  |   |   |   |--15.0.1
  |   |   |   |   |--dataconversion
  |   |   |   |   |   |--details.txt
  |   |   |   |--15.0.2
  |   |   |   |   |--dataconversion
  |   |   |   |   |   |--details.txt
  |   |   |--alloc_details.txt
  |   |--res
  |   |   |--resapp.zip
  |--REIM
  |   |--dataconversion
  |   |   |--dataconversioninstaller.zip
  |   |   |--rs_details.txt
  |   |--reim_bkp.zip
  |   |--hotfix
  |   |   |--mergedRC
  |   |   |   |--alloc
  |   |   |   |   |--p231.zip
  |--testfile1.txt
  |--testfile2.txt
  </code></pre>
  <p>is given as absolute paths (starting from the <strong>root directory</strong> and in a <strong>depth-first</strong> manner) in a <strong>python</strong> list as ( i.e., the paths are given as strings in a list) :-</p>
  <pre><code>['apc/','apc/data/', 'apc/data/datainstaller.zip', 'apc/data/rs_details/', 'apc/data/rs_details/readme.txt', 'apc/rem/', 'apc/rem/15.0.x/', 'apc/rem/15.0.x/15.0.1/', 'apc/rem/15.0.x/15.0.1/dataconversion/', 'apc/rem/15.0.x/15.0.1/dataconversion/details.txt', 'apc/rem/15.0.x/15.0.2/', 'apc/rem/15.0.x/15.0.2/dataconversion/', 'apc/rem/15.0.x/15.0.2/dataconversion/details.txt', 'apc/rem/alloc_details.txt', 'apc/res/', 'apc/res/resapp.zip', 'REIM/', 'REIM/dataconversion/', 'REIM/dataconversion/dataconversioninstaller.zip', 'REIM/dataconversion/rs_details.txt', 'REIM/reim_bkp.zip', 'REIM/hotfix/', 'REIM/hotfix/mergedRC/', 'REIM/hotfix/mergedRC/alloc', 'REIM/hotfix/mergedRC/alloc/p231.zip', 'testfile1.txt', 'testfile2.txt']
  </code></pre>
  <p>I want to create a nested dictionary to store this directory structure which would be something like this :-</p>
  <pre><code>  {
         'apc/': {
  
                  'apc/data/':{
                               'apc/data/datainstaller.zip' : {}
                                'apc/data/rs_details/' : {
                                              'apc/data/rs_details/readme.txt' : {}
                                           }
                            
                  'apc/rem/':{
                                  'apc/rem/15.0.x' : {
                                                  'apc/rem/15.0.x/15.0.1/': { 
                                                                               'apc/rem/15.0.x/15.0.1/dataconversion' : { 'apc/rem/15.0.x/15.0.1/dataconversion/details.txt' : {} }
                                           }
                                                  'apc/rem/15.0.x/15.0.2/': { 
                                                                               'apc/rem/15.0.x/15.0.2/dataconversion' : { 'apc/rem/15.0.x/15.0.2/dataconversion/details.txt' : {} }
                                           }
                               }
                         }
               }
     }
  </code></pre>
  <p>I tried to do it iteratively as well as recursively too by using the parameter as number of <code>/</code> in the path and finding prefix in the lower level directory paths but it resulted in an inconsistent nested dictionary and I could not get the desired one as shown above.</p>
  <p>Can anyone help me out with this?</p>
  <p>[Edit: <strong>The path string of directories always end with a <code>/</code> whereas the path string of files do not</strong>]</p>