title: Python: Make dictionary with folder names as key and file names as values
body: <p>I want to make a dictionary with folder names as key and file names as values
  for different files in different folders. Below is my code to achieve that, but I am not getting the expected output.</p>
  
  <p>I have a directory within that different folders are present. The directory name is <code>sreekanth</code>, within are many folders like <code>A</code>, <code>A1</code>, <code>A2</code>, <code>A3</code>, which contain <code>.csv</code> files.<br>
  I am trying to collect all the <code>.csv</code> files from the different folders and assigning them to the corresponding folder in a Python dictionary.</p>
  
  <pre class="lang-python prettyprint-override"><code>from os.path import os
  import fnmatch
  
  d={}
  
  l = []
  file_list = []
  file_list1 = []
  
  for path,dirs,files in os.walk('/Users/amabbu/Desktop/sreekanth'):
      for f in fnmatch.filter(files,'*.csv'):
          if os.path.basename(path) in d.keys():
              file_list.append(f)
              d = {os.path.basename(path):list(file_list)}
  
              print("First",d)
          else:
              d.setdefault(os.path.basename(path),f)
          print("Second",d)
  </code></pre>