-3

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

Tech
  • 3
  • 1
  • Welcome to StackOverflow! Please take the [tour], read [what's on-topic here](/help/on-topic), [ask], and the [question checklist](//meta.stackoverflow.com/q/260648), and provide a [mre]. "Implement this feature for me" is off-topic for this site. You have to _make an honest attempt_, and then ask a _specific question_ about your algorithm or technique. – Bharel Jan 29 '22 at 05:33
  • Welcome to Stack Overflow! Please take the [tour] and read [ask]. What's your question? You can [edit] to clarify. If you're looking for something simple that would just work for this situation, it shouldn't be too difficult, so what have you already tried? If you're looking for something more complex, have you looked at [`difflib`](https://docs.python.org/3/library/difflib.html)? – wjandrea Jan 29 '22 at 05:35

2 Answers2

0

you could use the SVN-Tortoise where this tool is part of the main installation for simple purposes, because your will be able to see it right away visually or if it you like to do it with python then difflib, some toy example from Doug Hellmann

import difflib from difflib_data import *

d = difflib.Differ() diff = d.compare(text1_lines, text2_lines) print('\n'.join(diff))

Dharman
  • 30,962
  • 25
  • 85
  • 135
baskettaz
  • 741
  • 3
  • 12
0

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.