human
Find the longest sub | Function to find longest prefix suffix.
To store longest prefix suffix.
Length of the previous longest prefix suffix.
lps [ 0 ] is always 0.
Loop calculates lps [ i ] for i = 1 to n - 1.
( pat [ i ] != pat [ Len ] ).
If Len = 0.
Function to find the longest substring which is prefix as well as a sub - of s [ 1. . . n - 2 ].
Find longest prefix suffix.
If lps of n - 1 is zero.
At any position lps [ i ] equals to lps [ n - 1 ].
If answer is not possible.
Driver code.
function call"
How can the above be solved in Python?

Write me a code to find the longest sub and the other steps required?
assistant
#Here is code to find the longest sub and the other steps required.
 def compute_lps ( s ) :
	n = len ( s )
	lps = [ 0 for i in range ( n ) ]
	Len = 0
	lps [ 0 ] = 0
	i = 1
	while ( i < n ) :
		if ( s [ i ] == s [ Len ] ) :
			Len += 1
			lps [ i ] = Len
			i += 1
		else :
			if ( Len != 0 ) :
				Len = lps [ Len - 1 ]
			else :
				lps [ i ] = 0
				i += 1
	return lps
def Longestsubstring ( s ) :
	lps = compute_lps ( s )
	n = len ( s )
	if ( lps [ n - 1 ] == 0 ) :
		print ( - 1 )
		exit ( )
	for i in range ( 0 , n - 1 ) :
		if ( lps [ i ] == lps [ n - 1 ] ) :
			print ( s [ 0 : lps [ i ] ] )
			exit ( )
	if ( lps [ lps [ n - 1 ] - 1 ] == 0 ) :
		print ( - 1 )
	else :
		print ( s [ 0 : lps [ lps [ n - 1 ] - 1 ] ] )
s = " fixprefixsuffix "
Longestsubstring ( s )