Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python find if strings have common substring

# credit to the Stack Overflow user in the source link

from difflib import SequenceMatcher

string1 = "apple pie available"
string2 = "come have some apple pies"

match = SequenceMatcher(None, string1, string2).find_longest_match(0, len(string1), 0, len(string2))

print(match)  # -> Match(a=0, b=15, size=9)
print(string1[match.a: match.a + match.size])  # -> apple pie
print(string2[match.b: match.b + match.size])  # -> apple pie
Comment

PREVIOUS NEXT
Code Example
Python :: python last element of list using reverse() function 
Python :: foreach loop in python with index 
Python :: get node name dynamo revit 
Python :: matmul shorthand numpy 
Python :: mechanize python #11 
Python :: check if set is a subset of another python 
Python :: sklearn model persistence 
Python :: comment interpreter tuple python avec valeur unique 
Python :: django rest DjangoModelPermissions include get 
Python :: return Response converting to string drf 
Python :: multiplication objects 
Python :: AI code for diagnosing diseases 
Python :: Add error message in django loginrequiredmixin 
Python :: windows use py instead of python 
Python :: # sort the dictionary 
Python :: python sorted vs sort 
Python :: load xgb 
Python :: pyttsx3 Running a driver event loop 
Python :: aws chalice 
Python :: Simple Example to Plot Python Treemap with lables 
Python :: numpy random sin 
Python :: python 3.9 32 bit 
Python :: empty python 
Python :: run flask in Jython 
Python :: keyword only arguments python 
Python :: how to murj record in django 
Python :: Python NumPy asfarray Function Syntax 
Python :: percentile of a score python 
Python :: add text to pdf file in python 
Python :: what are while loops in python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =