Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
ClosestCommonAncestor("A","C",x)
File "C:\x\x.py", line 149, in ClosestCommonAncestor
b = tree[otu2][0]
KeyError: ('ADBFGC', 14.5)
Dies ist die Funktion, die den Fehler zurückgibt.Weird Python Schlüssel Fehler
def ClosestCommonAncestor32 (otu1,otu2,tree):
while True:
a = tree[otu1][0][0]
while True:
b = tree[otu2][0]
if a == b:
return a
otu2 = b
otu1 = a
dies ist der Baum Eingang
{'A': [('AD', 4.0), None, None], 'C': [('ADBFGC', 14.5), None, None], 'B': [('BF', 0.5), None, None], 'E': [('ADBFGCE', 17.0), None, None], 'D': [('AD', 4.0), None, None], 'G': [('BFG', 6.25), None, None], 'F': [('BF', 0.5), None, None], 'ADBFG': [('ADBFGC', 6.25), ('AD', 4.25), ('BFG', 2.0)], 'BF': [('BFG', 5.75), ('B', 0.5), ('F', 0.5)], 'ADBFGC': [('ADBFGCE', 2.5), ('ADBFG', 6.25), ('C', 14.5)], 'ADBFGCE': [None, ('ADBFGC', 2.5), ('E', 17.0)], 'BFG': [('ADBFG', 2.0), ('BF', 5.75), ('G', 6.25)], 'AD': [('ADBFG', 4.25), ('A', 4.0), ('D', 4.0)]}
ich das nicht verstehen, dachte ich KeyError war, als es einen Schlüssel angefordert, die nicht existierten? Danke
Vermissen Sie nicht ein '[0]' in der Zeile 'b = tree [otu2] [0]'? (auch die Zeile 'otu1 = a' ist nicht erreichbar) – mgibsonbr