Find nodes with top degree centralities
In this exercise, you'll take a deeper dive to see whether there's anything interesting about the most connected students in the network. First off, you'll find the cluster of students that have the highest degree centralities. This result will be saved for the next plotting exercise.
Este exercício faz parte do curso
Intermediate Network Analysis in Python
Instruções do exercício
- Get the top 5 unique degree centrality scores. To do this, use the
sorted()
function, in which the first argument is the set of degree centrality values of G (because you want unique degree centralities), and the second argument isreverse=True
, to ensure that it is sorted in descending order. To limit the results to the top 5 scores, add in appropriate slicing to the end of the statement. Also, remember to use.values()
on the returned degree centrality results! - Create list of nodes that have the top 5 highest overall degree centralities. To do this:
- Iterate over the dictionary of degree centrality scores using the
.items()
method onnx.degree_centrality(G)
. - If
dc
is intop_dcs
, then append the noden
to thetop_connected
list.
- Iterate over the dictionary of degree centrality scores using the
- Print the number of nodes that share the top 5 degree centrality scores (
top_connected
) usinglen()
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Get the top 5 unique degree centrality scores: top_dcs
top_dcs = ____(set(____), reverse=True)[____:____]
# Create list of nodes that have the top 5 highest overall degree centralities
top_connected = []
for n, dc in ____:
if ____ in ____:
____
# Print the number of nodes that share the top 5 degree centrality scores
print(____)