title: Python for loop appends only the last list as value
body: <p>I am looping through a directory and want to get all files in a folder stored as list in a dictionary, where each key is a folder and the list of files the value.</p>
  
  <p>The first print in the loop shows exactly the output I am expecting. </p>
  
  <p>However the second print shows empty values. </p>
  
  <p>The third print after initialization of the class shows the list of the last subfolder as value for every key.</p>
  
  <p>What am I overlooking or doing wrong?</p>
  
  <pre><code>class FileAndFolderHandling() :
  
      folders_and_files = dict()
  
  
      def __init__(self) :
          self.getSubfolderAndImageFileNames()
  
  
      def getSubfolderAndImageFileNames(self) :
  
          subfolder = ""
          files_in_subfolder = []
  
          for filename in glob.iglob('X:\\Some_Directory\\**\\*.tif', recursive=True) :
  
              if not subfolder == os.path.dirname(filename) and not subfolder == "" :
                  print(subfolder + "  /  /  " + str(files_in_subfolder))
                  self.folders_and_files[subfolder] = files_in_subfolder   
                  files_in_subfolder.clear()
                  print(self.folders_and_files)
  
              subfolder = os.path.dirname(filename) # new subfolder
              files_in_subfolder.append(os.path.basename(filename))
  
  
  
  folder_content = FileAndFolderHandling()
  
  print(folder_content.folders_and_files)
  </code></pre>