human
I found an interesting problem on https://leetcode.com/problems/longest-happy-prefix/:
A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).
Given a string s. Return the longest happy prefix of s .
Return an empty string if no such prefix exists.
 
Example 1:
Input: s = "level"
Output: "l"
Explanation: s contains 4 prefix excluding itself ("l", "le", "lev", "leve"), and suffix ("l", "el", "vel", "evel"). The largest prefix which is also suffix is given by "l".

Example 2:
Input: s = "ababab"
Output: "abab"
Explanation: "abab" is the largest prefix which is also suffix. They can overlap in the original string.

Example 3:
Input: s = "leetcodeleet"
Output: "leet"

Example 4:
Input: s = "a"
Output: ""

 
Constraints:

1 <= s.length <= 10^5
s contains only lowercase English letters.

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is Python code to fix which is also a suffix (excluding itself).

class Solution:
    def longestPrefix(self, s: str) -> str:
        res, l, r , mod = 0,0,0, 10**9+7
        for i in range(len(s)-1):
            l = (l*128 + ord(s[i]))%mod
            r = (ord(s[~i])*(pow(128,i,mod)) + r)%mod
            if l==r: res = i+1
        return s[:res ]
        
   
        
        
        
    def longestPrefix_bychance_Brute(self, s: str) -> str:
        res = ''
        for i in range(1, len(s)):
            if s[:i]==s[-i:]:
                res =s[:i]
        return res