You forgot the first parameter to SequenceMatcher.

>>> import difflib
>>> 
>>> a='abcd'
>>> b='ab123'
>>> seq=difflib.SequenceMatcher(None, a,b)
>>> d=seq.ratio()*100
>>> print d
44.4444444444

http://docs.python.org/library/difflib.html

Answer from Lennart Regebro on Stack Overflow
🌐
Python
docs.python.org › 3 › library › difflib.html
difflib — Helpers for computing deltas
This is a class for comparing sequences of lines of text, and producing human-readable differences or deltas. Differ uses SequenceMatcher both to compare sequences of lines, and to compare sequences of characters within similar (near-matching) lines.
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › difflib.SequenceMatcher.html
difflib.SequenceMatcher — Python Standard Library
difflib.SequenceMatcher · View page source · class difflib.SequenceMatcher(isjunk=None, a='', b='', autojunk=True)[source]¶ · SequenceMatcher is a flexible class for comparing pairs of sequences of any type, so long as the sequence elements are hashable.
🌐
HexDocs
hexdocs.pm › difflib › Difflib.SequenceMatcher.html
Difflib.SequenceMatcher — Difflib v0.1.0
SequenceMatcher is a flexible module for comparing pairs of sequences of any type, so long as the sequence elements are hashable.
🌐
TestDriven.io
testdriven.io › tips › 6de2820b-785d-4fc1-b107-ed8215528f49
Tips and Tricks - Python - Using SequenceMatcher.ratio() to find similarity between two strings | TestDriven.io
https://docs.python.org/3/library/difflib.html#sequencematcher-objects · For example: from difflib import SequenceMatcher first = "Jane" second = "John" print(SequenceMatcher(a=first, b=second).ratio()) # => 0.5 · View All Tips · Feedback · × ·
🌐
Educative
educative.io › answers › what-is-sequencematcher-in-python
What is SequenceMatcher() in Python?
SequenceMatcher is a class that is available in the difflib Python package.
🌐
GeeksforGeeks
geeksforgeeks.org › python › compare-sequences-in-python-using-dfflib-module
Compare sequences in Python using dfflib module - GeeksforGeeks
February 24, 2021 - Python3 · # import required module import difflib # assign parameters par1 = 'gfg' par2 = 'GFG' # compare print(difflib.SequenceMatcher(None, par1, par2).ratio()) Output: 0.0 · The get_matching_blocks() method of this class returns a list of triples describing matching subsequences.
🌐
Coderz Column
coderzcolumn.com › tutorials › python › difflib-simple-way-to-find-out-differences-between-sequences-file-contents-using-python
difflib - Simple Way to Find Out Differences Between Sequences / File Contents using Python by Sunny Solanki
Our code for this example first creates an instance of SequenceMatcher using two sequences of integers. It then finds out the longest common subsequence using find_longest_match() and prints it. It then finds out the list of common subsequences using get_matching_blocks() and prints them. import difflib l1 = [1,2,3,5,6,7, 8,9] l2 = [2,3,6,7,8,10,11] seq_mat = difflib.SequenceMatcher(a=l1, b=l2) match = seq_mat.find_longest_match(alo=0, ahi=len(l1), blo=0, bhi=len(l2)) print("============ Longest Matching Sequence ==================") print("\nMatch Object : {}".format(match)) print("Matching S
Find elsewhere
🌐
GitHub
github.com › python › cpython › blob › main › Lib › difflib.py
cpython/Lib/difflib.py at main · python/cpython
Module difflib -- helpers for computing deltas between objects. · Function get_close_matches(word, possibilities, n=3, cutoff=0.6): Use SequenceMatcher to return list of the best "good enough" matches.
Author   python
🌐
Medium
medium.com › @zhangkd5 › a-tutorial-for-difflib-a-powerful-python-standard-library-to-compare-textual-sequences-096d52b4c843
A Tutorial of Difflib — A Powerful Python Standard Library to Compare Textual Sequences | by Kaidong Zhang | Medium
January 27, 2024 - You can complete a lot of text comparison work without leaving the Python environment. SequenceMatcher is a class in difflib that can be used to compare the similarity between two sequences (such as strings).
🌐
Runebook.dev
runebook.dev › en › docs › python › library › difflib › difflib.SequenceMatcher
python - SequenceMatcher Explained: Word-Level Diffs, Junk Handling, and Fuzzy Matching
difflib.SequenceMatcher is a class within Python's built-in difflib module that's designed to compare pairs of sequences (which are often strings of text, but can be lists of any hashable objects) to find the longest contiguous matching subsequence.
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › difflib.SequenceMatcher.__init__.html
difflib.SequenceMatcher.__init__ — Python Standard Library
difflib.SequenceMatcher » · difflib.SequenceMatcher.__init__ View page source · SequenceMatcher.__init__(isjunk=None, a='', b='', autojunk=True)[source]¶ · Construct a SequenceMatcher. Optional arg isjunk is None (the default), or a one-argument function that takes a sequence element and returns true iff the element is junk.
🌐
SourceForge
epydoc.sourceforge.net › stdlib › difflib.SequenceMatcher-class.html
difflib.SequenceMatcher - Epydoc - SourceForge
The same idea is then applied ... sequences, but does tend to yield matches that "look right" to people. SequenceMatcher tries to compute a "human-friendly diff" between two sequences....
🌐
PyPI
pypi.org › project › cdifflib
cdifflib · PyPI
from cdifflib import CSequenceMatcher import difflib difflib.SequenceMatcher = CSequenceMatcher import library_that_uses_difflib # Now the library will transparantely be using the C SequenceMatcher - other # things remain the same library_that_uses_difflib.do_some_diffing()
      » pip install cdifflib
    
Published   Jan 13, 2025
Version   1.2.9
🌐
Python Module of the Week
pymotw.com › 2 › difflib
difflib – Compare sequences - Python Module of the Week
The SequenceMatcher class compares two sequences of any types, as long as the values are hashable. It uses an algorithm to identify the longest contiguous matching blocks from the sequences, eliminating “junk” values that do not contribute to the real data. import difflib from difflib_data ...
🌐
Medium
ajinkya29.medium.com › what-is-difflib-41649066591c
What is Difflib?. So let's get started with this amazing… | by Ajinkya Mishrikotkar | Medium
June 14, 2021 - Difflib is a module that provides functions for comparing the sequences. It could be used for comparing strings and get additional information regarding them. 1. difflib.SequenceMatcher : Sequence Matcher is the class in the Difflib module.
🌐
Quora
quora.com › What-algorithm-is-Pythons-difflib-SequenceMatcher-based-on
What algorithm is Pythons' difflib SequenceMatcher based on? - Quora
Answer (1 of 2): According to ... This algorithm calculates string similarity based on the length of the longest common subsequence and recursive lengths of common characters in other parts ......
🌐
GitHub
github.com › mduggan › cdifflib
GitHub - mduggan/cdifflib: Python difflib with parts reimplemented in C
from cdifflib import CSequenceMatcher import difflib difflib.SequenceMatcher = CSequenceMatcher import library_that_uses_difflib # Now the library will transparantely be using the C SequenceMatcher - other # things remain the same library_that_uses_difflib.do_some_diffing()
Starred by 40 users
Forked by 7 users
Languages   C 65.3% | Python 32.7% | Makefile 2.0% | C 65.3% | Python 32.7% | Makefile 2.0%