I have a list of dictionaries that look something like this:
example = [
{'id': 1, 'foo': 10, 'seq': 1, 'val': 0, 'sum': 0} ,
{'id': 1, 'foo': 94, 'seq': 2, 'val': 5, 'sum': 5} ,
{'id': 1, 'foo': 32, 'seq': 3, 'val': 32, 'sum': 37} ,
{'id': 2, 'foo': 10, 'seq': 1, 'val': 0, 'sum': 0} ,
{'id': 2, 'foo': 43, 'seq': 2, 'val': 3, 'sum': 3} ,
{'id': 2, 'foo': 71, 'seq': 3, 'val': 14, 'sum': 17} ,
{'id': 2, 'foo': 32, 'seq': 4, 'val': 6, 'sum': 23} ,
{'id': 3, 'foo': 26, 'seq': 1, 'val': 0, 'sum': 0} ,
{'id': 3, 'foo': 38, 'seq': 2, 'val': 8, 'sum': 8}
]
I need three key pieces of information from the list:
1) I need to identify the highest "seq" value for each "id" in the list.
2) Using the results of (1), I need to compare the "sum" value for each highest "seq" value with the other highest "seq" values โโand determine which "seq" has the lowest "sum" ,.
3) This process is complicated by the fact that I also need to make a comparison based on the value of โfooโ, so the comparison in (2) only compares the values โโof โsumโ, where the first and last โfooโ values โโare the same.
, , "id" 1 2 , "foo" 10 "foo" 32.
- , , , , :
def getMinId(foo1, foo2, exampleList):
:
{(10,32): 23, (26,38): 8}
, , . , , - "sum" "foo" , , , .