I have the following defaultdict:
dictA = {"a": {"b": 0.1, "c": 0.2}, "b": {"c": 0.3}}
From this dict, I need to append the values to a list using the following combination of keys:
order = [("b","b"), ("b","a"), ("b","c"), ("a","b", ("a","a"), ("a","c"), ("c","b"), ("c","a"), ("c","c")]
If the keys combination are the same (for example ("a", "a")), the value should be zero. So the final result should look something like the following:
result = [0, 0.1, 0.3, 0.1, 0, 0.2, 0.3, 0.2, 0]
I have tried the following
dist = []
for index1, member1 in enumerate(order):
curr = dictA.get(member1, {})
for index2, member2 in enumerate(order):
val = curr.get(member2)
if member1 == member2:
val = 0
if member2 not in curr:
val = None
dist.append(val)
But obviously this is not working as intended. Can someone help me with this? Thank you