Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to compare two text files in python

with open('some_file_1.txt', 'r') as file1:
    with open('some_file_2.txt', 'r') as file2:
        same = set(file1).intersection(file2)

same.discard('
')

with open('some_output_file.txt', 'w') as file_out:
    for line in same:
        file_out.write(line)
Comment

PREVIOUS NEXT
Code Example
Python :: return max repeated value in list 
Python :: read live video from usb opencv python 
Python :: bar plot matplotlib 
Python :: pil image to numpy 
Python :: np.hstack 
Python :: Inheritance constructor with parameters python 
Python :: generic type python 
Python :: stack overflow python timedate 
Python :: python version installed in ubuntu 
Python :: django add model 
Python :: create models in django 
Python :: connect with pyodbc with statement 
Python :: multiple inputs in python 
Python :: python one line if else 
Python :: read a file and split the words python 
Python :: split a given number in python 
Python :: add pip to path 
Python :: pandas count freq of each value 
Python :: How to find xpath by contained text 
Python :: remove special characters from string python 
Python :: set pixel pygame 
Python :: how to pick out separate columns from the pandas dataframe object 
Python :: how to close a webpage using selenium driver python 
Python :: python append to csv on new line 
Python :: distinct rows in this DataFrame 
Python :: scroll horizontal excel 
Python :: Python make directories recursively 
Python :: numpy datetime64 get day 
Python :: make averages on python 
Python :: python try catch 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =