我正在尝试将依赖值附加到下面的列表中并遇到键错误...我在下面有预期的输出..任何人都可以提供关于这里有什么问题的输入吗?
'''
Current output without "+=" in internal_dep[num] +=dep_gerrit :-
{'313137': '12345', '99999': '', '34567': '99999', '12345': '34567'}
EXPECTED OUTPUT:-
{'313137': ['12345', '34567': '99999']}
'''
def findinternaldep(num):
if num == '313137':
output ='12345'
if num == '12345':
output = '34567'
if num == '34567':
output = '99999'
if num == '99999':
output = ''
return output
master_gerrit = ['313137']
internal_dep={}
for num in master_gerrit:
while True:
print "NUM"
print num
(dep_gerrit)=findinternaldep(num)
internal_dep[num] +=dep_gerrit
num = dep_gerrit
if dep_gerrit == '':
break
print internal_dep
错误:-
Traceback (most recent call last):
File "test_internal.py", line 34, in <module>
internal_dep[num] +=dep_gerrit
KeyError: '313137'