| |
| |
| """ |
| 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 |
|
|