title: python storing path names with forward vs backward slash
body: <p>I have a procedure that <code>os.walk</code>s a directory and its subdirectories to filter pdf files, separating out their names and corresponding pathnames. The issue I am having is that it will scan the topmost directory and print the appropriate filename e.g. <code>G:/Books/Title.Pdf</code> but the second it scans a subfolder e.g <code>G:/Books/Sub Folder/Title.pdf</code> it will print the following</p>
  
  <pre><code>G:/Books/Sub Folder\\Title.Pdf
  </code></pre>
  
  <p>(which is obviously an invalid path name).  It will also add \\ to any subfolders within subfolders.</p>
  
  <p>Below is the procedure:</p>
  
  <pre><code>def dicitonary_list():
      indexlist=[]        #holds all files in the given directory including subfolders
      pdf_filenames=[]    #holds list of all pdf filenames in indexlist
      pdf_dir_list = []   #holds path names to indvidual pdf files 
  
      for root, dirs,files in os.walk('G:/Books/'):
          for name in files:
              indexlist.append(root + name)
              if ".pdf" in name[-5:]:
                  pdf_filenames.append(name)
  
      for files in indexlist:
          if ".pdf" in files[-5:]:
              pdf_dir_list.append(files)
  
      dictionary=dict(zip(pdf_filenames, pdf_dir_list))       #maps the pdf names to their directory address
  </code></pre>
  
  <p>I know it's something simple that I am missing but for love nor money can i see what it is. A fresh pair of eyes would help greatly!</p>