Hello and thanks for your help. I have a list of dictionaries that looks like this:

```py
list_balls = [{'id': '803371', 'is_used': False, 'source': 'store', 'air': 0.9},
{'id': '803371', 'is_used': False, 'source': 'donation', 'air': 0.20},
{'id': '30042', 'is_used': False, 'source': 'donation', 'air': 0.75},
{'id': '803371', 'is_used': False, 'source': 'store', 'air': 1}]

```

I need to clean this list leaving unique list of dictionaries. If there is two entries or more with the same Id, I need to pick the one with the highest value on air. If they have equal values on air and ids, I need to leave the one where source == 'store'. Therefore, the result in this case would be

```py
list_balls = [{'id': '30042', 'is_used': False, 'source': 'donation', 'air': 0.75},
{'id': '803371', 'is_used': False, 'source': 'store', 'air': 1}]

```

I tried the following code to flag as keep = False for the ones that need to be taken out but it only works when there is two duplicates:

```py
for i in range(0, len(list_balls )):
    if len(list_balls ) > 1:
        #print(list_balls [i])
        for j in range(1, len(list_balls )):
            if (list_balls [i]['id'] == list_balls [j]['id']):
                if (list_balls [i]['air'] > list_balls [j]['air']):
                    list_balls [i]['keep'] = True
                    list_balls [j]['keep'] = False
print(list_pns)

```

I assume this double for loop is not the most efficient way to do this either so any other ideas are welcome. Thanks for your help