0

Hey I have dictionary like following one dicts = {'met_293': ['81.0175','4','7','7','29.76','23','1','0','22','28.57','2','[KG]EHY'],'met_394': ['79.9579','4','7','7','29.76','18','3','0','15','28.57','2','EHY[ILV]'],'met_309': ['81.0175','4','7','7','29.76','23','1','0','22','28.57','2','[KG]EHY'],'met_387': ['79.9579','4','7','7','29.76','18','3','0','15','28.57','2','EHY[ILV]']}

I want to remove keys which have same value like 'met_293' and 'met_309' those two keys have same value at 12th position which is '[KG]EHY' so i want my dictionary like this

{'met_293': ['81.0175','4','7','7','29.76','23','1','0','22','28.57','2','[KG]EHY'],'met_394': ['79.9579','4','7','7','29.76','18','3','0','15','28.57','2','EHY[ILV]']}

any help!!! thanks

2
Contributors
2
Replies
30
Views
3 Years
Discussion Span
Last Post by Pallab.Bhk
1

Here is one example:

import pprint as pp

mydic = {
'a123': [1, 2, 2, 4],
'a124': [1, 2, 3, 4],
'a125': [1, 2, 2, 4],
'a126': [1, 2, 4, 5]
}

newdic = {}
val_list = []
for key, val in mydic.items():
    if val not in val_list:
        newdic[key] = val
    val_list.append(val)

pp.pprint(newdic, width=50)

''' output -->
{'a123': [1, 2, 2, 4],
 'a124': [1, 2, 3, 4],
 'a126': [1, 2, 4, 5]}
'''
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.