0

How to code for Palindrome?

26th Dec 2017, 1:10 AM
Chaitanya
Chaitanya - avatar
4 odpowiedzi
+ 9
A palindrome is a string that reads the same backwards and forwards. In Python, you can use slice notation to reverse a string. Here is an example: "Hello"[::-1] == "olleH'
26th Dec 2017, 2:33 AM
David Ashton
David Ashton - avatar
+ 2
You could compare the first letter in your String with the last one and iterate to the middle as long as they are equal. You may should pay attention to words with an odd length. But the concept is a simple on. Here is an example: word: anna 1st iteration: a==a --> true 2nd iteration: n==n --> true 3rd iteration: no more letters left --> it's a palindrome next word: abcba 1st: a==a --> true 2nd: b==b --> true 3rd: one character left --> it's a palindrome next word: xyzzx 1st; x==x --> true 2nd: y==z --> false --> no palindrome Hope these are enough hints. If you have some issues following the hints, feel free to ask.
26th Dec 2017, 1:45 AM
Andreas K
Andreas K - avatar
+ 1
thanks peers!
26th Dec 2017, 3:40 AM
Chaitanya
Chaitanya - avatar