-2
「1234567890」の代わりにすべての整数を含める方法を教えてもらえますか?その場合、プログラムはトークンができるだけ多くの整数にあるかどうかをチェックします。深さより:すべての整数を含める方法はありますか?
for token in tokenList:
if token in "1234567890"
は、それがすべての整数の代わりに、 "1234567890"
を更新する必要があります。トークンリスト内のトークンは、「私は、言うことができるどのよう 『1234567890:』で トークン場合tokenListでトークン」:
代わりの トークンが整数である場合。
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)
あなたはすべての整数の文字列をしたいですか?それらのすべて? – khelwood
[変数が整数か文字列かどうかをチェックする方法は?](http://stackoverflow.com/questions/16488278/how-to-check-if-a-variable-is-an-integer- –
残念ながら、それは重複していません – user7959693