3.2.4.10. networkx.Graph.nodes_with_selfloops

Graph.nodes_with_selfloops()[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 : iterator

A iterator over nodes with self loops.

Examples

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