I have a python function that receives this 2 arguments:
list = [
{"id": "5", "name": "tomato", "value": 3},
{"id": "2", "name": "banana", "value": 2},
{"id": "4", "name": "tomato", "value": 2},
{"id": "1", "name": "banana", "value": 1.5},
{"id": "8", "name": "peas", "value": 1.5},
{"id": "7", "name": "peas", "value": 0.5}
]
"importance"={
"tomato": 2,
"banana": 1,
"peas": 6
}
I pre ordered the list based on value but now I want to order on the same value floor according to importance so it would look like in the end:
list = [
{"id": "5", "name": "tomato", "value": 3},
{"id": "4", "name": "tomato", "value": 2},
{"id": "2", "name": "banana", "value": 2},
{"id": "8", "name": "peas", "value": 1.5},
{"id": "1", "name": "banana", "value": 1.5},
{"id": "7", "name": "peas", "value": 0.5}
]
How can I do this using custom sort functions? Or is there any better way to do it?
"aroundimportancelistas a variable name in Python, since it masks the builtin with that name. Choose another name.