Output problem - with itertools.groupby in pyton : I got this homework question, after taking a course on udemy I still cannot figure out how to get the right output like the Solution.

furthermore:
and how can i make it more efficace
how can i do it without use explicit loops, but use list/dictionary comprehensions instead.

this is what i do:



def group_permutation_values(permutations_list): 

    dic = {}
    f = lambda x: x[1]
    for key, group in itertools.groupby(sorted(permutations_list, key=f), f):
        dic[key] = list(group)

    return dic
    
    pass

results = [((1, 2, 3), -4), ((1, 3, 2), -4), ((2, 1, 3), -2), ((2, 3, 1), -2), ((3, 1, 2), 0), ((3, 2, 1), 0)]
print(group_permutation_values(results))




this is what i got :
{-4: [((1, 2, 3), -4), ((1, 3, 2), -4)], -2: [((2, 1, 3), -2), ((2, 3, 1), -2)], 0: [((3, 1, 2), 0), ((3, 2, 1), 0)]}

and the expect output:
{-4: [(1, 2, 3), (1, 3, 2)], -2: [(2, 1, 3), (2, 3, 1)], 0: [(3, 1, 2), (3, 2, 1)]}