python求助:TypeError: 'NoneType' object is not iterable
#计算一个字符串中最长的 回文子串
s="abcicbads"
def create_echo(s):
temp,max_p,length="","",len(s)
for i in range(length):
left1,right1=i,i
def compare(l,r):
while l != -1 and r != length and s[l]==s[r]:
l,r=l-1,r+1
if l == -1 or r == length:
return s[l+1:r]
temp=compare(left1,right1)
if len(temp)>len(max_p): #此行报错TypeError: 'NoneType' object is not iterable
max_p=temp
if s[i]==s[i+1]:
left2,right2=i,i+1
temp=compare(left2,right2)
if len(temp)>len(max_p):
max_p=temp
return max_p
print(create_echo(s))
求各位大神解答