Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Is "A man a plan a canal Panama" a palindrome, if we ignore spaces and capital letters? How do you test it in Python?
Clean the text, then compare it with its reverse clean[::-1].
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Clean first. Make the letters small and keep only the letters: amanaplanacanalpanama.
Compare it with its reverse. clean[::-1] is amanaplanacanalpanama again. They are equal, so it is a palindrome.
The same test shows that "Hello world" is not: helloworld and dlrowolleh are different.
Log in to join the discussion.
Loading…