I have a function that returns the following dictionary
abc= {"type":"insecure","id":"1",
"name":"peter","s_count":"2",
"b_count":"1", "s_1_name":"melisa",
"s_1_id":"2","s_2_name":"graham",
"s_2_id":"4", "b_1_name":"henrik",
"b_1_id": "9"}
I want to chage the dictionary in the following way:
xyz={"type":"insecure","id":"1",
"name":"peter",
"s" : [{"id" : "2", "name": "melisa"},
{"id" : "4", "name": "graham"}],
"b" : [{"id" : "9", "name": "henrik"}]}
The logic is as follows: If there is s_count in dictionary then create a list that contains all the values that are starts with s. for example in my case create a a list which contain different dictionaries with each dictionary containing the s_name and s_id e.g in my case there are two dictionaries in the resulting list:
"s" : [{"id" : "2", "name": "melisa"},{"id" : "4", "name": "graham"}]
and do the same with b as well if b_count count exists.
can somebody help me out with that?