15,939,620 members
1.00/5 (1 vote)
See more:
https://i.stack.imgur.com/NMHmG.png[^]

What I have tried:

```s = 'abcbadhjhdana'
c = set(s)
d = []
b = "abcba"
for i in range(len(s)):
if s[i] in c:
print(s[i],c)
print(True)
if s[i] == s[a]:
if b == b[::-1]:
print(b,",",i,",",len(b))
else:
print("Not a pallindrome")
break
a += 1```
Posted
Updated 16-Dec-21 9:37am
CHill60 16-Dec-21 12:59pm
And what is wrong your code? What is the problem? What is your question?
Patrice T 16-Dec-21 13:41pm
What is the question ?

## Solution 1

Read the question carefully, and think about exactly what you need to do: look for palindromes starting at a particular index, and add them to a collection - then move to the next index and look through the rest of the line.

So the first thing you will need will be a collection, and probably a class to put in it, since you need to store two pieces of related information (start and length), and a function that takes a start and end index, plus a string and which checks for all palindromes between the start and end and adds them to the collection.

When that works, then call that starting with each possible index.

When that works, sort the collection.

Then finally, print the collection.

This isn't a complex task, if you think about for a little while and break it into smaller stages. This may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]