What index should i put in for the insert function in stack?
I am trying to write a program to check if entered string is a palindrome,
using the basic concept of stacks. I am confused what index to enter in
the stack1.insert function. Please help? Or do you think there is an even
more simpler approach to this?
def palindrome(str1):
stack1 = []
palInd = False
for chr in str1:
stack1.insert(0, chr)
for i in range(len(str1)-1):
if str1[i]==stack1.pop():
palInd = True
else:
palInd = False
return palInd
print palindrome("madam")
No comments:
Post a Comment