I have this dictionary, I want to get correesponding value of alias only if "type"="sorter" of dictionary values, if there is no sorter then get the value of maximum count.
for ex.
input
dct = {
"agg": [
{"count": 7, "type": "Aggregator", "alias": "Ag_ag"},
{"count": 2, "type": "Sorter", "alias": "So_so"},
],
"fil": [
{"count": 7, "type": "Filter", "alias": "fi_fu"},
{"count": 2, "type": "Aggregator", "alias": "ag_so"},
{"count": 2, "type": "expression", "alias": "ex_ex"},
]
}
output
{'agg':'So_so','fil':'fi_fu'}
I can achieve using
data_struct={
"agg": [
{"count": 7, "type": "Aggregator", "alias": "Ag_ag"},
{"count": 2, "type": "Sorter", "alias": "So_so"},
],
"fil": [
{"count": 7, "type": "Filter", "alias": "fi_fu"},
{"count": 2, "type": "Aggregator", "alias": "ag_so"},
{"count": 2, "type": "expression", "alias": "ex_ex"},
]
}
for key,value in data_struct.items():
for v in value:
#print(v)
if v.get("type")== 'Sorter':
rownum_dict[key] =v.get("alias")
pass
# to get max
max_item = max(value, key=lambda x: x['count'])
is there any simple way for this?