title: While comparing lists can you skip index that have been done in prev iteration?
body: <p>I am trying to compare two near identical files just one has missing entries and what is inside the parenthesis might be different. </p>
  
  <p>I am trying to iterate through all of the smaller list comparing to each entry in the larger list until it matches, copying the line into a new file if there is a match, and writing a blank line in the new file if there isn't yet. The problem is at each iteration it starts from the beginning I want it to skip the lines it has already checked from the previous iteration. Is there a way to do this or would it be better to delete lines from file as going along?</p>
  
  <pre><code>#opening of files
  fh = open('sampleparsefile.txt', "r")
  fh2 = open('sampleparsefile2.txt', "r")
  f = open('compared', 'w')
  #fhw = open('sampleparsefile.txt', "w")
  
  
  
  # Make each line a list split at open '('
  line1Split = [line1.split('(')[0] for line1 in fh.readlines()]
  line2Split = [line2.split('(')[0] for line2 in fh2.readlines()]
  print(line1Split)
  print(line2Split)
  
  
  # iterate through line2Split
  # for item2 in line2Split:
  for item2 in line2Split:
      #splitSingleLine = [aVariable.split('(')[0]]
  
  
      # Set a variable to false
      founditem = False
      # iterate through each entry in line1Split comparing
      # to item in line2Split
      for item1 in line1Split:
          # While match is not found
          # boolean variable set to false
          while (founditem == False):
              # if they match write the match to a file and break
              # change boolean variable to true if matched
              if item1 == item2:
                  founditem = True
                  # if there is a newline character strip it
                  # if there isn't continue on
                  if '\n' in str(item2):
                      x = item2.split('\n')[0]
                      f.write(str(x))
                      break
                  else:
                      f.write(item2)
                      # WAS HERE but thinking deleting lines from original file would not be good idea
                      #fhw = open('sampleparsefile.txt', "w")
                      #for aLines in fhw.readlines:
                      #    if item1 != item2:
                      #        line1Split.pop[0]
                      break
                      # also will want to remove found entry from line2split
                      # that way following passes wont search same first lines
                      # will also need to re-attach what was in parenthesis
                      # before writing to file
                      # if match is not found write a new line to file and break
              else:
                      f.write('\n')
                      break
  fh.close()
  fh2.close()
  f.close()
  
  #Sampleparsefile.txt sample ignore all #
  # Data1
  # Data2
  # Data3(a)
  # Data4(ab)
  # Data5(ABC)
  # Data6
  # Data7
  # Data8(a)
  # Data9(a)
  
  #Sampleparsefile.txt sample
  # Data1
  # Data3(a)
  # Data5(ABC)
  # Data6
  # Data8(A)
  # Data9(a)
  
  #Desired Result - for now just whats before brackets
  # Data1
  #
  # Data3(ABC)
  # 
  # Data5(A)
  # Data6
  # 
  # Data8(a)
  # Data9(a)
  
  #Actual Result
  # Data1
  #
  # Data3
  #
  #
  #
  # Data5
  # 
  #
  #
  #
  # Data6
  #
  #
  #
  #
  #
  #
  # Data8
  #
  #
  #
  #
  #
  #
  #
  # Data9
  </code></pre>