Compare 2 files and discard common lines

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Jun 3 03:49:47 CEST 2008


2008/5/29, loial <jldunn2000 at googlemail.com>:
>> 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.

En Thu, 29 May 2008 18:08:28 -0300, BJörn Lindqvist <bjourne at gmail.com>  
escribió:

> Open('3rd','w').writelines(set(open('2nd').readlines())-set(open('1st')))

Is the asymmetry 1st/2nd intentional? I think one could omit .readlines()  
in 2nd file too.

-- 
Gabriel Genellina




More information about the Python-list mailing list