# Python3 code to demonstrate working of
# Convert list of dictionaries to Dictionary Value list
# Using loop
from collections import defaultdict
import numpy as np
# initializing lists
# list_temp = [{"Gfg" : 6},
# {"Gfg" : 8},
# {"Gfg" : 2},
# {"Gfg" : 12},
# {"Gfg" : 22}]
list_temp =[]
a = {"a" : 1}
aa = {"a" : 2}
b = {"b" : 1}
bb = {"b" : 3}
for i in range(4):
list_temp.append(a)
list_temp.append(aa)
list_temp.append(b)
list_temp.append(bb)
# printing original list
print("The original list : " + str(list_temp))
# using loop to get dictionaries
# defaultdict used to make default empty list
# for each key
res = defaultdict(list)
for sub in list_temp:
for key in sub:
res[key].append(sub[key])
# printing result
print("The extracted dictionary : " + str(dict(res)))
average_a = np.mean(res["a"])
print(f"Average score of a {average_a}")