列表顺序不符合预期

The order of list is not as expected

我有一个列表 node_list

In [1]: node_list
Out[1]: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1, 2, 3, 4, 5, 6]

我从 node_list

添加节点到 NetworkXG
In [2]: import networkx as nx

In [3]: G = nx.Graph()

In [4]: G.add_nodes_from(node_list)

但是当我得到节点列表时,模式就变了!

In [5]: list(G.nodes())
Out[5]: ['a', 1, 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'j', 2, 3, 4, 6, 5]

我希望 Out[5]node_list 具有相同的模式,但这并没有发生。怎么做到的?

From the docstring,共 NetworkX.Graph

Examples
--------
Create a graph object that tracks the order nodes are added.
>>> from collections import OrderedDict
>>> class OrderedNodeGraph(nx.Graph):
...     node_dict_factory=OrderedDict
>>> G=OrderedNodeGraph()
>>> G.add_nodes_from( (2,1) )
>>> G.nodes()
[2, 1]
>>> G.add_edges_from( ((2,2), (2,1), (1,1)) )
>>> G.edges()
[(2, 1), (2, 2), (1, 1)]