这就是我的输入的样子:
cust1Attributes = [{'Key': 'FirstName', 'Value': 'SomeFirstName'}, {'Key': 'LastName', 'Value': 'SomeLastName'}]
这是我的MandatoryData列表的样子:
class MustHaveData(object):
def __init__(self, name, defaultValue):
self.name = name
self.defaultValue = defaultValue
customerMandatoryData=[]
customerMandatoryData.append(MustHaveData(name="FirstName", defaultValue="Default First Name"))
customerMandatoryData.append(MustHaveData(name="LastName", defaultValue="Default Last Name"))
customerMandatoryData.append(MustHaveData(name="State", defaultValue="Default State"))
我需要将cust1Attributes's key
与customerMandatoryData's name
进行比较,并获取customerMandatoryData
的{{1}}列表,而不是cust1Attributes
我该怎么做?
答案 0 :(得分:2)
从包含每个custset = {x['Key'] for x in cust1Attributes}
result = [obj for obj in customerMandatoryData if obj.name not in custset]
的项目的字典中构建集,并使用列表解析过滤掉集合中名称的对象:
distance.execute(graphModel, attributeModel);