Вы можете сделать что-то вроде этого:
def get(d, first, second):
return d.get(second, {}).get(first, 0.0)
dictA = {"a": {"b": 0.1, "c": 0.2}, "b": {"c": 0.3}}
order = [("b", "b"), ("b", "a"), ("b", "c"), ("a", "b"), ("a", "a"), ("a", "c"), ("c", "b"), ("c", "a"), ("c", "c")]
result = [get(dictA, first, second) or get(dictA, second, first) for first, second in order]
print(result)
Вывод
[0.0, 0.1, 0.3, 0.1, 0.0, 0.2, 0.3, 0.2, 0.0]
Или менее pythonic альтернатива:
def get(d, first, second):
return d.get(second, {}).get(first, 0.0)
dictA = {"a": {"b": 0.1, "c": 0.2}, "b": {"c": 0.3}}
order = [("b", "b"), ("b", "a"), ("b", "c"), ("a", "b"), ("a", "a"), ("a", "c"), ("c", "b"), ("c", "a"), ("c", "c")]
result = []
for first, second in order:
value = get(dictA, first, second)
if value:
result.append(value)
else:
value = get(dictA, second, first)
result.append(value)
print(result)
Выход
[0.0, 0.1, 0.3, 0.1, 0.0, 0.2, 0.3, 0.2, 0.0]