1a Write a Python code for a palindrome tester using two sta
1a. Write a Python code for a palindrome tester using two stacks. You will need to handle strings that may have upper/lower case letters and white space between the letters. We will not include punctuation marks in our strings. Some examples would include strings like “ Ot t o”, “ABCcbA”, “A Man a Plan a canal Pana Ma”
1b. after you have written this code Repeat the above problem, but this time, write a palindrome tester using a stack and a queue.
Solution
Code:
import os
import sys
def checkpalstack(st):#using stack
stack1=[]
stack2=[]
stack1=list(st)
stack2=list(st)
for i in range(len(st)):
if stack1[i]!=stack2.pop():
return 0
return 1
def checkpalqueue(st):#using queue
stack=[]
queue=[]
stack=list(st)
queue=list(st)
for i in range(len(st)):
if stack.pop()!=queue[i]:
return 0
return 1
print checkpalstack(\"abba\")
print checkpalqueue(\"abba\")
