- list is below
- preference dictionary is below
- if all the keys and values except
type
will be same then .. - Need to compare
type
in each list which is highest order in preference dictionary - Output is list of dictionary which type is highest order
list_ = [
{
"id": "11",
"name": "son",
"email": "n@network.com",
"type": "Owner"
},
{
"id": "11",
"name": "son",
"email": "n@network.com",
"type": "Manager"
},
{
"id": "21",
"name": "abc",
"email": "abc@network.com",
"type": "Employ"
},
{
"id": "21",
"name": "abc",
"email": "abc@network.com",
"type": "Manager"
}
]
A preference dictionary = {'Owner': 1, 'Manager':2, 'employ':3, 'HR': 4 }
My output dictionary below
[{'id': '11', 'name': 'son', 'email': 'n@network.com', 'type': 'Owner'},
{'id':'21','name': 'abc','email': 'abc@network.com','type': 'Manager'}]
new_list = []
for each in list_:
if each['type'] in priority.keys():
if each['id'] not in new_list:
new_list.append(each)
from How to create a priority list of dictionary
No comments:
Post a Comment