title: Comparing first file to rest line by line - python beginner
body: <p>I recently started learning python and wanted some help please. I wanted to compare the first file in a directory to other files in the same directory. I recently learend about loops so I wanted to do this project using only for loops and no fancy functions like intersection, which I found using Google.</p>
  
  <p>Here is my code so far. What I'm having problems with is implementing the counter. I would like the counter to increase by 1 after the first two files have been compared. In my mind, this would allow for the first file to then be compared to the third file in the directory. </p>
  
  <p>Eventually I want to have two counters, one for the first file and one for the second. Once the first file has been compared to all files in the directory, the first file counter would increase by 1 and the loop would restart and now the second file would be compared to file 3, then file 4 etc.. and so forth.</p>
  
  <p>Thanks for any help!</p>
  
  <pre><code>path = ("/my/dir/")
  files = os.listdir( path )
  number_files = len(files)
  
  while (n &lt; (number_files)):
      count = 1
      file1 =  open(path+files[0], 'r')
      file1read = file1.read().splitlines() 
      file2 = open(path+files[count], 'r')
      file2read = file2.read().splitlines() 
      for i in file1read:
          for j in file2read:
              if i == j:
                  print (os.path.basename(file1.name)+"_"+os.path.basename(file2.name)+" have {} in common".format(j))
                  count = count + 1
                  n = n + 1
          else:
              count = count + 1
              n = n + 1
  </code></pre>