NetworkX

Previous topic

networkx.Graph.nodes

Next topic

networkx.Graph.__iter__

networkx.Graph.nodes_iter

Graph.nodes_iter(data=False)

Return an iterator over the nodes.

Parameters:

data : boolean, optional (default=False)

If False the iterator returns nodes. If True return a two-tuple of node and node data dictionary

Returns:

niter : iterator

An iterator over nodes. If data=True the iterator gives two-tuples containing (node, node data, dictionary)

Notes

If the node data is not required it is simpler and equivalent to use the expression ‘for n in G’.

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_path([0,1,2])
>>> for n in G:
...     print n,
0 1 2

Examples

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_path([0,1,2])
>>> for n in G.nodes_iter():
...     print n,
0 1 2
>>> for n,d in G.nodes_iter(data=True):
...     print d,
{} {} {}