I have the following list after querying my DB which I'd like to turn into a dictionary:
[{date: date_value1.1, rate: rate_value1.1, source: source_name1},
{date: date_value1.2, rate: rate_value1.2, source: source_name1},
{date: date_value2.1, rate: rate_value2.1, source: source_name2},
{date: date_value2.2, rate: rate_value2.2, source: source_name2},
{date: date_valuenx, rate: rate_valuex, source: source_namex}, ...]
The dictionary should follow the following format:
{
source_name1:
[
{date: date_value1.1, rate: rate_value1.1}
{date: date_value1.2, rate: rate_value1.2}
],
source_name2:
[
{date: date_value2.1, rate: rate_value2.1}
{date: date_value2.2, rate: rate_value2.2}
],
}
I have tried a lot of different code variations, but could not get it to work. What would be the most efficient way to transform the data into the required format?
(This format is the response the client will receive after calling my API. If you have suggestions for better formatting of this response I am also open to suggestions!)