In Python you can simply use graph.select() (atleast when reading the documentation:
If you just need a list of the neighbouring nodes:
ego(g, order=1, node="1", mindist=0)
# [[1]]
# 4/10 vertices, named, from 00cfa70:
# [1] 1 4 6 9
CodePudding user response:
I think the method using ego
(by @user20650) is comprehensive and efficient.
Here is another option if you would like to find the sub-graph built on direct neighbors, which applies distances
induced_subgraph
> induced_subgraph(g, which(distances(g, "1") <= 1))
IGRAPH 99f872b UN-- 4 3 -- Erdos renyi (gnp) graph
attr: name (g/c), type (g/c), loops (g/l), p (g/n), name (v/n)
edges from 99f872b (vertex names):
[1] 1--4 1--6 1--9