I am learning the networkx library and I came across this (source code is here)
sorted(d for n, d in G.degree())
which sorts the degrees of nodes in graph G. I don't quite understand this, especially d for n: what does n mean here?
I am learning the networkx library and I came across this (source code is here)
sorted(d for n, d in G.degree())
which sorts the degrees of nodes in graph G. I don't quite understand this, especially d for n: what does n mean here?
This is shorthand for
lst = []
for n, d in G.degree():
lst.append(d)
lst.sort()
So, G.degree is expected to return a set of tuples with two elements, where the second one has degrees. You're just collecting those values and sorting them.