【发布时间】:2017-10-01 21:02:19
【问题描述】:
谁能告诉我如何包含所有整数而不是“1234567890”。因此,在这种情况下,程序将检查令牌是否为尽可能多的整数。
for token in tokenList:
if token in "1234567890"
需要全部为整数而不是“1234567890”
更新:更深入。
而不是“for tokenList 中的令牌: 如果令牌在“1234567890”中 我怎么说,“对于令牌列表中的令牌: 如果令牌是整数。
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)
【问题讨论】:
-
你想要一个所有整数的字符串?全部?
-
很遗憾,它不是重复的
标签: python python-2.7 python-3.x wxpython ipython