human
Naive algorithm for Pattern Searching | Python3 program for Naive Pattern Searching algorithm.
A loop to slide pat [ ] one by one.
For current index i , check for pattern match.
if pat [ 0. . . M - 1 ] = txt [ i , i + 1 , ... i + M - 1 ].
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to naive algorithm for Pattern Searching and the other steps required.
 def search ( pat , txt ) :
	M = len ( pat )
	N = len ( txt )
	for i in range ( N - M + 1 ) :
		j = 0
		while ( j < M ) :
			if ( txt [ i + j ] != pat [ j ] ) :
				break
			j += 1
		if ( j == M ) :
			print ( " Pattern ▁ found ▁ at ▁ index ▁ " , i )
if __name__ == ' _ _ main _ _ ' :
	txt = " AABAACAADAABAAABAA "
	pat = " AABA "
	search ( pat , txt )