I have the following list of dicts:
list_of_dicts = [
{"type": "X", "hour": 22},
{"type": "A", "measure": "1"},
{"type": "B", "measure": "2"},
{"type": "X", "hour": 23},
{"type": "A", "measure": "3"},
{"type": "X", "hour": 24},
{"type": "A", "measure": "4"},
{"type": "B", "measure": "5"},
{"type": "C", "measure": "6"}
]
How can I split it into a dict where keys are the 'hour' values from 'type' = 'X' dicts and values are the other dicts between two 'type' = 'X' dicts? That's what I want to obtain using this example, but the interval between two 'type' = 'X' dicts can be variable.
dict_of_dicts = {
22: [
{"type": "A", "measure": "1"},
{"type": "B", "measure": "2"},
],
23:[
{"type": "A", "measure": "3"}
],
24:[
{"type": "A", "measure": "4"},
{"type": "B", "measure": "5"},
{"type": "C", "measure": "6"},
]
}
Thanks in advance!