Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

brute force string matching algorithm in python

1 def BF(s1,s2):
 2     """ BF algorithm """
 3     i = 0
 4     j = 0
 5     while(i < len(s1) and j < len(s2)):
 6         if(s1[i] ==  s2[j]):
 7             i += 1
 8             j += 1
 9         else:
10             i = i - j + 1
11             j = 0
12     if(j >= len(s2)):
13         return i - len(s2)
14     else:
15         return 0
16  
17 if __name__ == "__main__":
18     a1="abcaaaabbbbcccabcbabdbcsbbbbnnn"
19     a2='ccabcba'
20     b=BF(a1,a2)
21     print(b)
22     s1 = "ababcabcacbab"
23     s2 = "abcac"
24     print(BF(s1,s2))
Comment

PREVIOUS NEXT
Code Example
Python :: pyqt set focus 
Python :: python remove dtype from array 
Python :: palindrome words python 
Python :: python ascii to string 
Python :: python str of list 
Python :: how to print a newline in python 
Python :: Python - How To Check Operating System 
Python :: python max value in list 
Python :: python Sort the dictionary based on values 
Python :: requirement.txt for python 
Python :: how to configure a button in python tkinter 
Python :: django sessions for beginners 
Python :: list out the groups from groupby 
Python :: unsupervised knn 
Python :: get discord guild members discord.py 
Python :: django changing boolean field from view 
Python :: python keyboard input 
Python :: how to get the number of rows and columns in a numpy array 
Python :: sns.heatmap 
Python :: ValueError: `logits` and `labels` must have the same shape, received ((None, 10) vs (None, 1)). 
Python :: How to Pass Additional Context into a Class Based View in django 
Python :: change column values based on another column pandas 
Python :: cookies in django 
Python :: most common letter in string python 
Python :: convert excel to pdf python 
Python :: python strptime milliseconds 
Python :: django jsonresponse 
Python :: how to end a while loop python 
Python :: match case in python 
Python :: glob.glob python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =