Python Sequence Matcher

engrmahabub
Mahabubur Rahman
Published on Jan, 03 2024 1 min read 0 comments
image

🖥 class difflib.SequenceMatcher: This module provides classes and functions for comparing sequences. 

This module provides classes and functions for comparing sequences. It can be used for example, for comparing files, and can produce information about file differences in various formats, including HTML and context and unified diffs. For comparing directories and files, see also, the filecmp module.

from difflib import SequenceMatcher

t1 = input('Sentence 1: ')
t2 = input('Sentence 2: ')

sequenceScore = SequenceMatcher(None,t1,t2).ratio()

print(f"Both sencence are {sequenceScore*100}% similar")

 

Sentence 1: 
we love programming
Sentence 2: 
python programming awesome
Both sencence are 57.77777777777777% similar

 

https://docs.python.org/3/library/difflib.html

 

0 Comments