def spc(sym): stk1=myStack() stkall=myStack() sym=sym.split() for i in sym: if i not in stk1: stk1.push(i) else: stkall.push(i) print(list(stk1)) print(list(stkall)) for j in stk1: for k in stkall: if j==k: stk1.pop(j) and stkall.pop(k) else: pass if stk1.size == stkall.size: print("all symbols match") else: print("these symbols, have no matches", list(stk1))
spc(‘{{‘) #this must return symbols have no matches spc(‘{}’) #this must return symbols are matching
Below is my stack class
class myStack: def __init__(self): def isEmpty(self): return self.size() == 0 def push(self, item): self.container.append(item) def pop(self, item): return self.container.pop(item) def size(self): return len(self.container) def __iter__(self): return iter(self.container)
Please help me get the right output, What i want to achieve is for parenthesis and all symbols to be properly balanced in that not only does each opening symbol have a corresponding closing symbol, but the types of symbols match as well.