列表中的公式不一致

2024-06-25 13:42:36 发布

您现在位置: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我希望它被检测到。它也有而不是q和q。你知道吗

类似地,第二个列表具有非(p或q)和(p或q)。有人能提出解决这个问题的办法吗?这可能很简单,但我似乎想不起来。你知道吗

理想情况下,是否可以将子列表标记为已关闭?也许分配状态已关闭?你知道吗


Tags: orbox消息示例列表not情况能力
1条回答
网友
1楼 · 发布于 2024-06-25 13:42:36

这就是我在问题中提出的问题的解决办法。工作正确,如果有人可以改善它或使它更短(或更快),请做你的主张后。你知道吗

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);

相关问题 更多 >