compare List of attributes against an object inside list
<p>This is how my Input looks like:</p>

<pre><code>cust1Attributes = [{'Key': 'FirstName', 'Value': 'SomeFirstName'}, {'Key': 'LastName', 'Value': 'SomeLastName'}]
</code></pre>

<p>This is how my MandatoryData list looks like:</p>

<pre><code>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"))
</code></pre>

<p>I need to compare <code>cust1Attributes's key</code> against <code>customerMandatoryData's name</code> and get the list of <code>customerMandatoryData</code> back which does not exist for <code>cust1Attributes</code></p>

<p>How do i do this?</p>

<p>Build a <em>set</em> from the dictionary containing the items at each <code>Key</code> and use a <em>list comprehension</em> to filter out objects with names in the set:</p>

<pre><code>custset = {x['Key'] for x in cust1Attributes}
result = [obj for obj in customerMandatoryData if obj.name not in custset]
</code></pre>

python