当给出具有以下内容的边列表时,我试图在图中打印不同的节点:
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
?