type
will be same then ..type
in each list which is highest order in preference dictionarylist_ = [
{
"id": "11",
"name": "son",
"email": "[email protected]",
"type": "Owner"
},
{
"id": "11",
"name": "son",
"email": "[email protected]",
"type": "Manager"
},
{
"id": "21",
"name": "abc",
"email": "[email protected]",
"type": "Employ"
},
{
"id": "21",
"name": "abc",
"email": "[email protected]",
"type": "Manager"
}
]
A preference dictionary = {'Owner': 1, 'Manager':2, 'employ':3, 'HR': 4 }
My expected output dictionary below
[{'id': '11', 'name': 'son', 'email': '[email protected]', 'type': 'Owner'},
{'id':'21','name': 'abc','email': '[email protected]','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)
You can simply do src.sort(key = lambda x : preference[x["type"]])
and your list will be sorted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With