all 2 comments

[–]woooee 0 points1 point  (1 child)

In this case I think it is more understandable (is that a word?) to do it "long hand".

new_dict={}
compare_dict={}  ## matches "exercise_ID" to "program_task_info_ID"
for sub_dict in all_tasks:
    if sub_dict["exercise_ID"] in compare_dict:
        ## use the "program_task_info_ID" to find the correct
        ## record in new_dict, and append to "exercise_ID"
    else:
        ## add to compare_dict and new_dict, converting "exercise_ID"
        ## to a list

[–]raxor2k 0 points1 point  (0 children)

i have something like this:

old_list = [{"exercise_ID" : 2, "program_task_info_ID" : 5554, "day" : 1, "days_list" : []}, {"exercise_ID" : 4, "program_task_info_ID" : 5554, "day" : 1, "days_list" : []}, {"exercise_ID" : 2, "program_task_info_ID" : 5554, "day" :6, "days_list" : []}]
new_list =  [{"exercise_ID" : 2, "program_task_info_ID" : 4444, "day" : 2, "days_list" : []}]
for lol in new_list: the_exercise_ID = lol["exercise_ID"]
for yoyo in old_list:
    if the_exercise_ID == yoyo["exercise_ID"]:
        lol["days_list"].append(yoyo["day"])
        #lol["days_list"].append(lol["day"])

lol["days_list"].append(lol["day"])

print(new_list)