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 :: text size legend to bottom matplotlib 
Python :: how to convert string to date object in python 
Python :: codeforces 677a solution 
Python :: pandas casting into integer 
Python :: list count frequency python 
Python :: how to use enumerate instead of range and len 
Python :: matplotlib show percentage y axis 
Python :: python- number of row in a dataframe 
Python :: get adjacent cells in grid 
Python :: numpy replace 
Python :: python enum declare 
Python :: python live radio 
Python :: how to multiply two tuples in python 
Python :: pandas merge multiple dataframes 
Python :: how to change a thread name in python 
Python :: run 2 loops simultaneously python 
Python :: python not null 
Python :: python selenium get title 
Python :: hot reloading flask 
Python :: how to get location of word in list in python 
Python :: plt normalized histogram 
Python :: force utf-8 encoding python 
Python :: scrapy user agent 
Python :: converting datetime object format to datetime format python 
Python :: huggingface default cache dir 
Python :: python print without leading whitespace 
Python :: pyperclip copy paste 
Python :: print hello world python 
Python :: how to check which python version is installed 
Python :: find max value index in value count pandas 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =