Python: How to compare values of different keys in dictionary and then delete duplicates?
<p>I am parsing over 100 files that follow the same format. For example for one file, I have a dictionary consisting of two keys and multiple values in a list. </p>

<pre><code>   temp2 = {
  '0.1995': ['X3:GATE', 'IN1', 'IN1', 'X7:GATE', 'X4:GATE', 'IN2', 'IN2', 'X8:GATE'],
  '0.399': ['X4:GATE', 'Y', 'Y', 'X3:GATE', 'Y', 'X8:SRC', 'X1:GATE', 'IN0', 'IN0', 'X5:GATE']
</code></pre>

<p>Here is the code that creates the temp2 dictionary:</p>

<pre><code>#temp_delvt_list, temp_pin_list is from an external function
for delvt, pin in zip(temp_delvt_list, temp_pin_list):
                temp[delvt].append(pin) #dictionary with delvt and pin names for cell

            for line in SPFFile1:
#                   print line
                for delvt_keys,pin_values in temp.items():
#                   if re.match('[RC].*(?:i%s)' % '|'.join(pin_values), line): //couldn't get working
                    if re.search('(?i)' '|'.join(pin_values),line) and re.match('R',line):
                        #print delvt_keys
                        line_split = line.split(" ")
                        temp_list.append(delvt_keys)
                        temp_list.append(delvt_keys) #duplicated to create balanced list with temp_search_list
                        temp_search_list.append(line_split[1])
                        temp_search_list.append(line_split[2])
#                       print temp_list
#                       print temp_search_list
            SPFFile1.close()
            for d, p in zip(temp_list, temp_search_list):
                #print temp2[d]
            #   print re.sub(':SRC',':ISI',p)
                temp2[d].append(p) #dictionary with delvt and pin names for cell
#           print temp2

}
</code></pre>

<p>I am trying to search the values for each key and then for the key (0.1995) with no Y-values delete all values that appear for that key that also appear in the key (0.399) that has the Y values.The key values are not hardcoded and may change.</p>

<p>The output should be:</p>

<pre><code>temp2 = {
  '0.1995': ['X3:GATE', 'IN1', 'IN1', 'X7:GATE', 'X4:GATE', 'IN2', 'IN2', 'X8:GATE'],
  '0.399': ['Y', 'Y','Y', 'X8:SRC', 'X1:GATE', 'IN0', 'IN0', 'X5:GATE']
}
</code></pre>

<p>Here is the code I have figured out so far:</p>

<pre><code>        for test_d, test_p in temp2.items():
            if not re.search('Y', ' '.join(test_p)) :
                for x in test_p:
                    print x
            else:
                for y in test_p:
                    print y
</code></pre>

<p>Where I think I should replace the print statement with either lists that I compare either other to. </p>
