-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion32-
56 lines (23 loc) · 886 Bytes
/
Question32-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def check_pelidrome(input_string):
return input_string==input_string[::-1]
def giving_space(input_string):
a = ""
for i in input_string:
a+=i+" "
return a[:-1]
def recursive_palindrome(input_string):
result=[giving_space(input_string)]
len_input_string = len(input_string)
for i in range(len_input_string):
for j in range(i+2, len_input_string+1):
if check_pelidrome(input_string[i:j]):
a = giving_space(input_string[:i]) +" "+ input_string[i:j] +" "+ giving_space(input_string[j:])
a = a.strip()
result.append(a)
if check_pelidrome(input_string):
if input_string not in result:
result.append(input_string)
return result
if __name__ == "__main__":
input_string = "nitin"
print(recursive_palindrome(input_string))