Reputation: 33
paliList=[1,3,2,5,5,6,2,3,1]
listlen=len(paliList)
hallist=int(l/2)
i=0
c=0
while(a):
while(c<=a):
while(l>i):
while(paliList[i]==paliList[l-1]):
i+=1
l-=1
print('List is not palindrome')
c+=1
Hi, above is my piece of code to find whether the list is Palindrome (rather elements in the list are in palindrome). I have having difficulty printing the message 'List is not palindrome'. I tried printing this message here and there but not able to conclude.
Upvotes: 0
Views: 246
Reputation: 54173
For any iterable, you can check if it's a palindrome by doing:
all(i==j for i,j in zip(some_iter, reversed(some_iter)))
For any object that supports slicing, you can do:
some_iter == some_iter[::-1]
Upvotes: 4