I have written a program to find the longest palindrome in a given string. The problem is that I want to eliminate all instances of index variables to make the program more "pythonic". I have used enumerate to hold the index for each character in the input string, but I'm not sure how to eliminate the search index. Can anyone offer some insight. any tips on improving the program would be appreicated. thanks.
def isPALINDROME(input):
lastINDEX=len(input)-1
for i, each in enumerate(input):
if input[i]==input[lastINDEX]:
lastINDEX-=1
else:
return False
return True
def findLONGEST_palindrome(input):
list=[]
strlen=len(input)-1
for i, each in enumerate(input):
j=i+1
try:
while input[i]!=input[j]:
j+=1
if input[i]==input[j]:
list.append(input[i:j+1])
except IndexError:
pass
return list
out=findLONGEST_palindrome("ASDFASDFDS12345678987654321ASDFjj")
for each in out:
if isPALINDROME(each):
print each