I'm working on a project where I have to loop through a series of objects. Each object has numerical data linked to it regarding the distance each object relative to another object in the program. To do this I was thinking a list of dictionaries would be best. So for example these are the objects and numerical value associated with them:
a: 10, b: 5, c: 7
My issue is I have to find the object with the lowest number which I will be doing by using the min() method but after doing this I need to pull back the object name related to the minimum value to run another function on it and remove it from the list before reiterating through the list again to find the next lowest value.
I was thinking a list of dictionaries would be best to handle this but I have no idea how to compare the numerical data to get the minimum value and pull back the related object name. Each time the program is run the list can contain a different number of objects generated randomly.
[
{"a": 10},
{"b": 5},
{"c": 7}
]
In the example above I would want it to identify b as the lowest value then pull back the object associated with the lowest value to run a function on that object then remove it from the list before looping through it again to remove the next lowest value which in the case above would be c.
Is this achievable and if so how could I go about doing this?