我试图确定字典中是否存在特定的键和值对;但是,如果我使用contains或has key方法,它只检查键。我需要它来检查键和特定值。一些背景:我们总共有4个字典:一个用于A、B、CompareList和ChangeList。一旦A被初始化,我将A的内容放入比较列表(我将直接比较它们;但是A和B是双哈希表)。我试过这里所有的方法,但没有一个对我有用)。所以一旦我们将a放入comparelist中,我将它与b中的objecttributes字典进行比较,看看是否有什么变化。例如,B可能有键,值对shape:circle和fill:no。如果compareList有shape:circle和fill:yes,那么我只希望fill:yes是changelist。问题在于"if attributes.getname()不在self.compareList中:"行。这是代码;我在Python2.7.8上运行它。提前感谢您的帮助!!
class ObjectSemanticNetwork:
def __init__(self):
self.ObjectNames = {}
self.ObjectAttributes = {}
def setName(self, name):
self.ObjectNames[name] = self.ObjectAttributes
def setData(self, name, attribute):
self.ObjectAttributes[name] = attribute
def checkData(self, key):
print(key)
for key, value in self.ObjectAttributes.iteritems():
print(key)
print(value)
print("
")
class Agent:
(self):
self.CompareList = {}
self.ChangeListAB = {}
self.ChangeListCD = {}
def addToCompareList(self, name, value):
self.CompareList[name] = value
def addToChangeListAB(self, name, value):
se