Compare 2 files and discard common lines

Stefan Behnel stefan_ml at behnel.de
Thu May 29 04:54:01 EDT 2008


loial wrote:
> I have a requirement to compare 2 text files and write to a 3rd file
> only those lines that appear in the 2nd file but not in the 1st file.

   lines_in_file2 = set(open("file2").readlines())
   for line in open("file1"):
       if line not in lines_in_file2:
           print line

Stefan



More information about the Python-list mailing list