title: Compare lines of 2 input files, and output third file with differences
body: <p>I have a function working that allows me to enter two files text files, compares these text files, and finally creates a third file with the differences. It works for each line within a file, and for it to work, the whole line of text must be similar in file 1 and file 2 for it to register. This is my problem, I wish to compare the lines based only on the first word behind the colon for the lines to the similar - the text after the colons doesn't need to be the same.</p>
  
  <p>The structure of the files are like so;</p>
  
  <p>File 1 example:</p>
  
  <pre><code>A:dog 
  B:cat 
  C:bird 
  D:cow 
  E:pig
  </code></pre>
  
  <p>File 2 example:</p>
  
  <pre><code>B:sheep
  D:duck
  </code></pre>
  
  <p>I wish the ouput of the newly created file (File 3) to have the contents of:</p>
  
  <pre><code>A:dog
  C:bird
  E:pig
  </code></pre>
  
  <p>I would like the function to output the entries from file 1 that aren't in file 2 based only upon the first string (letter) before the semicolon. This currently only works if the entire line of text within File 2 is identical to File 1:</p>
  
  <pre><code>def comparison(F1,F2,F3):
     with open(F1, 'r') as f:
        d=set(f.readlines())
     with open(F2, 'r') as f:
        e=set(f.readlines())
     open(F3, 'a').close()
     with open(F3, 'a') as f:
        for line in list(d-e):
           f.write(line)
  
  comparison('file1.txt','file2.txt','file3.txt')
  </code></pre>
  
  <p>I have mainly tried using <code>line.split(':')[0]</code> to grab the first string before the colon to compare, but haven't been successful. </p>