I'm trying to parse this list to get a single List[dict] containing the dicts with data for all metric types.
metrics_info = [
{
"metric_type1": [
{
"name": "m10",
"score": "11"
},
{
"name": "m20",
"score": "790"
}
]},
{
"metric_type2": [
{
"name": "m30",
"score": "245"
}
]}
]
For now I've created a method that allows to get a list of dicts for a specific metric type:
def parse_metrics(metrics_info: List[dict], metric_type: str) -> List[dict]:
for item in metrics_info:
if metric_type in item:
return item[metric_type]
How can I get a List[dict] containing the inner dictionaries for all metric types?
The result should look like this:
[
{
"name": "m10",
"score": "11"
},
{
"name": "m20",
"score": "790"
},
{
"name": "m30",
"score": "245"
}
]