Python Dictionary: compare 2 values in 1 key
<p>I have a dataset where there is a list of names in a column, and a response for each name in a separate column. Each name is listed twice, and I want to see if there is agreement between the two recorded responses. 
i.e.</p>

<p>name a | response 1</p>

<p>name a | response 2</p>

<p>name b | response 1</p>

<p>name b | response 2</p>

<p>I created a dictionary where the key has two values. The dictionary creates the name as the key, and each response as a value. I want to create a list to see if response1 = response2, or if response1 != response2. Here is what I have so far:</p>

<pre><code>myDict = {}
if name not in myDict.keys():
    myDict[name] = {'response1': answer}
else:
    myDict[name]['reponse2'] = answer

match = True
for items in hospitalDict:
    if hospitalDict[items] != hospitalDict[items]:
          match = False
print match
</code></pre>

<p>I am stuck on this part...any advice on how to construct this? I would also like to output this data to a csv eventually.</p>

<p>you can use groupby and customer key function to separate two groups    </p>

<pre><code>   from itertools import groupby
   myDict = {
        'name 1' : {'response1':'A', 'response2':'B'},
        'name 2' : {'response1':'C', 'response2':'C'},
        'name N' : {'response1':'Z', 'response2':'Z'},
    }

    for i in groupby(myDict.items(),key = lambda x: x[1]['response1'] == x[1]['response2']):
        print i[0],list(i[1])

    True [('name N', {'response2': 'Z', 'response1': 'Z'}), ('name 2', {'response2': 'C', 'response1': 'C'})]
    False [('name 1', {'response2': 'B', 'response1': 'A'})]
</code></pre>

python python-2.7 dictionary key