0

次のようなプレフィックス表記で条件ステートメントを評価する必要があります。

condition = ('AND', 'NE','$type','email','EQ','$link','space')

そのうち:- 'AND','NE', 'EQ'etc は論理演算子です - AND, Not equal to (NE), EQ (equal to)

自動的に評価するために、「AND」と「OR」を除く演算子モジュールから演算子の残りを取得できます。誰かが提案できますか?以下の詳細な説明(より適切に実装できるかどうか教えてください):

条件の評価中、$ で始まるものは、入力辞書から文字列に等しいキーに置き換えられます ($' を削除した後)。

Input = {'type': 'email', 'link' : 'tab' }

operator モジュールを使用して、次のような二項演算を評価できます。

subst_op = []
Inp = {'type': 'email', 'link' : 'tab' }

# substitute input parameters
for cond in condition:
    subst_op.append(Inp[cond[1:]] if '$' in cond else cond)

#while input, start from right pushing operands on to stack and if operator, pop two operands, evaluate with the operator and push on to stack (http://en.wikipedia.org/wiki/Polish_notation)
....
# for evaluation, use the operator module
if condition in ('NE','EQ' ..)
    getattr(operator, condition)(popped_operand1,popped_operand2)

演算子に「AND」と「OR」がありません。提案してください。

4

0 に答える 0