'Returns an iterator over selfloop edges.
A selfloop edge has the same node at both ends.
Parameters
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\')
default : value, optional (default=None)
Value used for edges that dont 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.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_edge(1, 1)
>>> G.add_edge(1, 2)
>>> list(G.selfloop_edges())
[(1, 1)]
>>> list(G.selfloop_edges(data=True))
[(1, 1, {})]'

def selfloop_edges(self, data=False, default=None):

    if (data is True):
        return ((n, n, nbrs[n]) for (n, nbrs) in self._adj.items() if (n in nbrs))
    elif (data is not False):
        return ((n, n, nbrs[n].get(data, default)) for (n, nbrs) in self._adj.items() if (n in nbrs))
    else:
        return ((n, n) for (n, nbrs) in self._adj.items() if (n in nbrs))
