Click here to Skip to main content
15,939,620 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:[^]

What I have tried:

s = 'abcbadhjhdana'
c = set(s)
d = []
b = "abcba"
for i in range(len(s)):
    if s[i] in c:
    if s[i] == s[a]:
        if b == b[::-1]:
            print("Not a pallindrome")
a += 1
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 ?

1 solution

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[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900