for neighb in G.neighbors(root):
    others = [n for n in G.neighbors((1, 1)) if n != neighb]
for other in others:
    if neighb in [x for x in G.neighbors(other) if x != root]:
        in_loop.add(neighb)
break
NetworkX - путь вокруг узла