forked from seeditsolution/pythonprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongestPalindrome
More file actions
22 lines (22 loc) · 502 Bytes
/
longestPalindrome
File metadata and controls
22 lines (22 loc) · 502 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
t= int(input())
for k in range(t):
str=input()
substring=[]
for i in range(len(str)):
for j in range(i+1,len(str)+1):
substring.append(str[i:j])
pal=[]
for i in range(0,len(substring)):
temp=substring[i]
temp1=temp[::-1]
if (temp==temp1):
pal.append(temp)
max=""
for i in range(0,len(pal)):
if((len(pal[i])>len(max)) and (len(pal[i])>1)):
max=pal[i]
elif(len(max)<=1):
max=pal[0] #max=str[:1]
print(max)
substring.clear()
pal.clear()