Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notes : Code to count average significant actual score of specific connections out of all pairs (from dictionary), which have key #32

Open
ihgumilar opened this issue Sep 22, 2022 · 1 comment

Comments

@ihgumilar
Copy link
Owner

ihgumilar commented Sep 22, 2022

# 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}")
@ihgumilar ihgumilar changed the title Notes : Count average significant actual score of specific connections out of all pairs (from dictionary), which have key Notes : Code to count average significant actual score of specific connections out of all pairs (from dictionary), which have key Sep 22, 2022
@ihgumilar
Copy link
Owner Author

ihgumilar commented Oct 3, 2022

Run this code, when all significant actual scores into a list first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant