我想給邊緣的列表與以下時打印的不同節點圖:Python:爲什麼這個列表中的一個元素沒有被打印?
def find_nodes(graph):
# get the distinct nodes from the edges
nodes = []
l = len(graph)
for i in range(l):
edge = graph[i]
n1 = edge[0]
n2 = edge[1]
if n1 not in nodes:
nodes.append(n1)
if n2 not in nodes:
nodes.append(n2)
return nodes
graph = ((1,2),(2,3), (3,1))
print find_nodes(graph)
但我只得到(1,2)
如何我失去了3
?
它爲我打印'[1,2,3]'。 – 2012-07-15 19:36:26
同樣在這裏:http://ideone.com/NhyFb – 2012-07-15 19:37:33
使用Windows命令提示符......這可能是相關的嗎? – algorithmicCoder 2012-07-15 19:38:54