What would be the loop content in the for loop?
a=raw_input("Enter a string :")
print a
length = len(a)
p = a[::-1]
print p
if a == p:
print "palindrome"
else:
print "Not palindrome"
for i in range(len(a)):
What would be the loop content in the for loop?
a=raw_input("Enter a string :")
print a
length = len(a)
p = a[::-1]
print p
if a == p:
print "palindrome"
else:
print "Not palindrome"
for i in range(len(a)):
Check whether the length of the string is odd or even. If odd try to preserve the middle character.
if len(s)%2:
return s[:len(s)//2] + s[len(s)//2] + s[:len(s)//2][::-1]
else:
return s[:len(s)//2] + s[:len(s)//2][::-1]
This checks if string s is a palindrome
s='hiih'
s[0:int(len(s)/2)] == s[int(len(s)/2):len(s)][::-1]