Python stack Builtin

import queue
st = queue.LifoQueue(maxsize = len(s)+10)

when I use this on snippet for implementing stack application for parenthesis check of I am getting TLE. Is there any alternative stack implementation in python.
problem link https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1/

Just use a list as a stack. Both append and pop are O(1).

2 Likes

yes use list as a stack.
heres how to use it :

stack = []
stack.append(4)
stack.append(10)
print(stack.pop())  #prints 10
print(stack.pop()) # prints 4
2 Likes