test2.py 370 B

1234567891011121314
  1. import difflib
  2. # Read the contents of the two files
  3. with open('file2.txt') as f1, open('file2.txt') as f2:
  4. text1 = f1.read()
  5. text2 = f2.read()
  6. # Compare the sequences of characters in the two files
  7. # and compute their similarity
  8. matcher = difflib.SequenceMatcher(None, text1, text2)
  9. similarity = matcher.ratio()
  10. # Print the similarity score
  11. print(similarity)