I have a file at a certain location, which was generated by python code. I want to run the same code, to generate another file, but with the same name and the same location, so it will replace the first one. Before running the code, I saved the initial file contents to a string. After running the code, I saved the final file contents to another string. How could I compare data_initial and data_final strings as file contents and to highlight exactly what words differ in those two strings? I tried like this:
data_initial="1234"
data_final="12345 new thing"
first_set = set(data_initial)
second_set = set(data_final)
difference = first_set.symmetric_difference(second_set)
But this gives me:
difference is
{'t', 'n', ' ', 'i', '5', 'e', 'h', 'w', 'g'}
I would like to see the words which are different, like
12345 new thing
Also if it's possible to check for each phrase that changed.