I have two text files that i'd like to compare and have any similaritie listed in a new file. For example, if one file contains "123:example:example" and another file contains "123" and "example", i would want "123" and "example" to count as the same and to be listed in a new file. I think that I need to use a split function to have it split at the colon, but I am unsure where I can put that. I tried putting it where the splitlines() is, but that gives an error saying an integer is needed. I am very new to python so any advice or hints are appreciated!
This currently works, but only for lines without colons.
#choose the two files to open
#read the two files, intersection method returns set that
contains similarity
file1 = set(open('file1.txt').read().lower().splitlines())
file2 = set(open('file2.txt').read().lower().splitlines())
same = file1.intersection(file2)
#any matches are listed in a new file
with open('result.txt', 'a') as new_file:
for line in same:
new_file.write(line + '\n')
More complete example:
**File 1:**
123:example:test
testing
abc
**file2:**
test
456:testing
ABC
**desired output in new file:**
test
testing
abc