Session Ready
Exercise

Find the most popular forums day-by-day: II

Great work with the previous exercise - you had written code that created the time-series graph list. Now, you're going to finish that exercise - that is, you'll find out how many forums had the most popular forum score on a per-day basis!

One of the things you will be doing here is a "dictionary comprehension" to filter a dictionary. It is very similar to a list comprehension to filter a list, except the syntax looks like: {key: val for key, val in dict.items() if ...}. Keep that in mind!

Instructions
100 XP
  • Get the degree centrality using nx.bipartite.degree_centrality(), with G_sub and forum_nodes as arguments.
  • Filter the dictionary such that there's only forum degree centralities. The key: val pair in the output expression should be n, dc. Iterate over dc.items() and check if n is in forum_nodes.
  • Identify the most popular forum(s) - should be of highest degree centrality (max(forum_dcs.values())) and its DC value should not be zero.
  • Append the highest dc values to highest_dcs.
  • Create the plots!
    • Use a list comprehension for the first plot, in which you iterate over most_popular_forums (which is a list of lists) using forums as your iterator variable. The output expression should be the number of most popular forums, calculated using len().
    • For the second plot, use highest_dcs and plt.plot() to visualize the top degree centrality score.