Can someone please show me how to include all integers instead just "1234567890". So in that case the program will check if token is in as much integers as possible.
for token in tokenList:
if token in "1234567890"
need it to be all integers instead of "1234567890"
Update: more in depth.
Instead of "for token in tokenList: if token in "1234567890" How can I say, "for token in token list: if token is in integers.
def infixToPostfix(infixexpr):
prec = {}
prec["**"] = 3
prec["*"] = 3
prec["/"] = 3
prec["+"] = 2
prec["-"] = 2
prec["("] = 1
prec[")"] = 1
opStack = Stack()
postfixList = []
tokenList = infixexpr.split()
for token in tokenList:
if token in "1234567890":
postfixList.append(token)
elif token == '(':
opStack.push(token)
elif token == ')':
topToken = opStack.pop()
while topToken != '(':
postfixList.append(topToken)
topToken = opStack.pop()
else:
while (not opStack.isEmpty()) and \
(prec[opStack.peek()] >= prec[token]):
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return " ".join(postfixList)