Skip to content
Advertisement

Displaying the difference between two files [closed]

I am learning Python, and have a query. Sorry for inconvenience.
I have 2 text files as follow :
File1.txt:

1
2
3

File2.txt:

1
2
3
4 

I want to print what’s unique in File2.txt, the output should be 4. It would be great if it would be a python script.
Thanks in advance

Advertisement

Answer

Giving you the exact code would not help you in learning, so let me give you hint which you can explore:

Read about readlines() in python -> It opens a text file and reads all the lines and saves them back in a list.
Read about finding difference between two lists ->stackoverflow solution

Once you are able to figure out both of these, you should be able to achieve the result you are aiming for.
Thank You.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement