Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.classes.function.nodes_with_selfloops

nodes_with_selfloops(G)[source]

Returns an iterator over nodes with self loops.

A node with a self loop has an edge with both ends adjacent to that node.

Returns

nodelist – A iterator over nodes with self loops.

Return type

iterator

Examples

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1, 1)
>>> G.add_edge(1, 2)
>>> list(nx.nodes_with_selfloops(G))
[1]