列表中的公式不一致 python
inconsistent formulaes in the list python
所以问题涉及存储不同命题模态公式的列表列表。我能够删除重复项,但我不知道如何找到不一致之处。例如:
列表的初始列表:
[[('not', ('box', 'p')), ('box', 'p'), ('not', 'q'), ('q'), ('diamond', 'r')],
[('not', 'p'), 'q'], ['or', ('p', 'q')],
['not',('or', ('p', 'q'))],['r', 'q']]
上面的列表示例列表有一些问题我想简单地找到它们并打印出一条消息。对于 示例,第一个列表包含框 p 和取反框
p 我希望它被检测到。它也有 not q 和 q。
类似地,第二个列表有not (p or q) and (p or q)。任何人都可以提出解决这个问题的方法,这可能很简单,但我似乎无法想到。
理想情况下,是否可以将子列表标记为已关闭?也许分配状态已关闭?
这是我在问题中提出的问题的解决方案。工作正常,如果有人可以改进它或使其更短(或更快),请post你的提议。
def inconsistent(psi):
for i in range(0,len(psi)):
for j in range(0,len(psi[i])):
main = psi[i]
form = psi[i][j]
if form[0] == 'not':
notform = form[1]
if form and notform in main:
print "inconsistent: ", psi[i][j]
else:
notform = ('not', psi[i][j])
if form and notform in main:
print "inconsistent: ", psi[i][j]
else:
print "consistent: ", psi[i][j]
test = [[('not', ('box', 'p')), ('box', 'p'), ('not', 'q'), ('q'), ('diamond', 'r')], [('or', ('p', 'q')),('not',('or',('p','q')))],['not',('or', ('p', 'q'))],['r', 'q']]
inconsistent(test);
所以问题涉及存储不同命题模态公式的列表列表。我能够删除重复项,但我不知道如何找到不一致之处。例如:
列表的初始列表:
[[('not', ('box', 'p')), ('box', 'p'), ('not', 'q'), ('q'), ('diamond', 'r')],
[('not', 'p'), 'q'], ['or', ('p', 'q')],
['not',('or', ('p', 'q'))],['r', 'q']]
上面的列表示例列表有一些问题我想简单地找到它们并打印出一条消息。对于 示例,第一个列表包含框 p 和取反框 p 我希望它被检测到。它也有 not q 和 q。
类似地,第二个列表有not (p or q) and (p or q)。任何人都可以提出解决这个问题的方法,这可能很简单,但我似乎无法想到。
理想情况下,是否可以将子列表标记为已关闭?也许分配状态已关闭?
这是我在问题中提出的问题的解决方案。工作正常,如果有人可以改进它或使其更短(或更快),请post你的提议。
def inconsistent(psi):
for i in range(0,len(psi)):
for j in range(0,len(psi[i])):
main = psi[i]
form = psi[i][j]
if form[0] == 'not':
notform = form[1]
if form and notform in main:
print "inconsistent: ", psi[i][j]
else:
notform = ('not', psi[i][j])
if form and notform in main:
print "inconsistent: ", psi[i][j]
else:
print "consistent: ", psi[i][j]
test = [[('not', ('box', 'p')), ('box', 'p'), ('not', 'q'), ('q'), ('diamond', 'r')], [('or', ('p', 'q')),('not',('or',('p','q')))],['not',('or', ('p', 'q'))],['r', 'q']]
inconsistent(test);