I am a newbie in python . Guys I have written one function which checks that the list is palindrome or not but I wanted to replace it with pure looping statements .Do u have any solution or do I have to use recursive function compulsorily .
import json
def reverse(x):
if isinstance(x, list):
return [reverse(x) for x in x[::-1]]
return x
def palindrome(x):
return x == reverse(x)
st=raw_input("Enter List : ")
lst=json.loads(st)
print palindrome(lst)
check this...
>>> def palindrome(n):
return n == n[::-1]
>>> palindrome('chk')
False
>>> palindrome('chc')
True
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With