Skip to main content
`Ctrl`+`K`

# selfloop_edges

selfloop_edges(G, data=False, keys=False, default=None)

  Returns an iterator over selfloop edges.

  A selfloop edge has the same node at both ends.

  Parameters:
    G graph

      A NetworkX graph.

    data string or bool, optional (default=False)

      Return selfloop edges as two tuples (u, v) (data=False) or three-tuples (u, v, datadict) (data=True) or three-tuples (u, v, datavalue) (data=’attrname’)

    keys bool, optional (default=False)

      If True, return edge keys with each edge.

    default value, optional (default=None)

      Value used for edges that don’t have the requested attribute. Only relevant if data is not True or False.

  Returns:
    edgeiter iterator over edge tuples

      An iterator over all selfloop edges.

  See also

  `nodes_with_selfloops`, `number_of_selfloops`

  Examples

      >>> G = nx.MultiGraph()  # or Graph, DiGraph, MultiDiGraph, etc
      >>> ekey = G.add_edge(1, 1)
      >>> ekey = G.add_edge(1, 2)
      >>> list(nx.selfloop_edges(G))
      [(1, 1)]
      >>> list(nx.selfloop_edges(G, data=True))
      [(1, 1, {})]
      >>> list(nx.selfloop_edges(G, keys=True))
      [(1, 1, 0)]
      >>> list(nx.selfloop_edges(G, keys=True, data=True))
      [(1, 1, 0, {})]