Can someone help me with my queue? I think the stack works fine.
I just need the indexing of the queue or do I need to index the queue?

from string12 import *
from queue import *

def main():
    stack1 = Stack()
    queue = Queue()

    word = raw_input("Enter a word or number sequence to check for palidrom: ")

    l_case = word.lower()
    s_case = word.lower()

    pallist1 = []
    pallist2 = []
    print l_case
    print s_case
    
    index = 0
    while index < len(l_case):
        letter = l_case [index]
        stack1.push(letter)
        index +=1

    while not stack1.isEmpty():
        pallist1.append(stack1.pop())
    print pallist1

    indexs = 0
    while indexs > len(s_case):
        butter = s_case [index]
        queue.enqueue(butter)
        indexs +=1

    while not queue.isEmpty():
        pallist2.append(queue.dequeue())
    print pallist2

    string1 = "".join(pallist1)
    string2 = "".join(pallist2)

    print string1
    print string2
    
    if string1 == string2:
        print "Palindrome"
    else:
        print "No Palindrome"

main()

Recommended Answers

All 3 Replies

You only need to check if reversed string equals the normal one. To use stack and queue you can do comparision until first failure during reading back. Should not take more than 10 lines of code.

If you can not use a built-in method to reverse the string (or list if you prefer), please state what the requirements are, otherwise:
reverse_word = input_word[::-1] ## [begin:end:step=-1]

Thanks I seen my errors and shortened it with functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.