EX_GRAPH1 = {0:[1,4,5],
1:[2,6],
2:[3],
3:[0],
4:[1],
5:[2],
6:[]
}
이 함수 (사전로 표현) 유향 그래프 이중 음자 을 취하여 그래프에서 노드 인 -도를 계산한다.IndexError : 범위 밖의리스트 인덱스 (그렇지리스트, 사전 있어야)
def compute_in_degrees(digraph):
in_degrees = {}
i = 0
j = 0
matches = []
while i < len(digraph):
m = 0
while j < len(digraph):
if digraph[i][j] == i: <--- HERE IndexError: list index out of range
j += 1
m += 1
matches.append(m)
else:
j += 1
in_degrees[i] = matches
i += 1
return in_degrees
print compute_in_degrees(EX_GRAPH1)
제발 도와
'while j
jonrsharpe