Spaces:
Sleeping
Sleeping
File size: 618 Bytes
e94100d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
https://docs.python.org/3/library/difflib.html
https://blog.csdn.net/stone0823/article/details/112310176
"""
import difflib
text1 = '''
I love HaiYan
I very love HaiYan
She's the one I love the most.
'''
text2 = '''
I love LiWang
I very love LiWang
I'm his favorite person.
'''
d = difflib.Differ()
result = d.compare(text1, text2)
result = "".join(list(result))
print(result)
seq_match = difflib.SequenceMatcher(None, text1, text2)
ratio = seq_match.ratio()
print(ratio)
match = seq_match.get_matching_blocks()
print(match)
if __name__ == "__main__":
pass
|