【发布时间】:2016-06-20 06:56:53
【问题描述】:
我是编程的初学者,我是新来的,所以你好!
我在 networkX 中遇到节点顺序问题。 这段代码:
letters = []
G = nx.Graph()
for i in range(nodesNum):
letter = ascii_lowercase[i]
letters.append(letter)
print letters
G.add_nodes_from(letters)
print "G.nodes = ", (G.nodes())
返回这个:
['a']
['a', 'b']
['a', 'b', 'c']
['a', 'b', 'c', 'd']
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e', 'f']
['a', 'b', 'c', 'd', 'e', 'f', 'g']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
G.nodes = ['a', 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'j']
虽然我希望它按正常(字母顺序)顺序排列。 谁能告诉我我做错了什么? 顺序对我很重要,因为稍后我会要求用户告诉我边缘在哪里。
提前致谢!
【问题讨论】:
-
请参阅stackoverflow.com/questions/15479928/…,了解有关此情况发生原因的更多信息。 NetworkX 使用 python 字典来存储节点。
标签: python python-2.7 graph nodes networkx