MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / naivePatternSearch

Function naivePatternSearch

strings/naiveStringSearch.py:10–22  ·  view source on GitHub ↗
(mainString,pattern)

Source from the content-addressed store, hash-verified

8 m=length of pattern string
9"""
10def naivePatternSearch(mainString,pattern):
11 patLen=len(pattern)
12 strLen=len(mainString)
13 position=[]
14 for i in range(strLen-patLen+1):
15 match_found=True
16 for j in range(patLen):
17 if mainString[i+j]!=pattern[j]:
18 match_found=False
19 break
20 if match_found:
21 position.append(i)
22 return position
23
24mainString="ABAAABCDBBABCDDEBCABC"
25pattern="ABC"

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected