Python: How To Compare Values Of Different Keys In Dictionary And Then Delete Duplicates?
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. temp2 = { '0.1995
Solution 1:
Probably you are looking for
>>> 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']
}
>>> _set = set(temp2['0.1995'])
>>> temp2['0.399'] = [e for e in temp2['0.399'] if e not in _set]
>>> import pprint
>>> pp = PrettyPrinter(indent = 4)
>>> pp.pprint(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']}
>>>
Post a Comment for "Python: How To Compare Values Of Different Keys In Dictionary And Then Delete Duplicates?"