Exercise

The bipartite keyword

In the video, Eric introduced you to the 'bipartite' keyword. This keyword is part of a node's metadata dictionary, and can be assigned both when you add a node and after the node is added. Remember, though, that by definition, in a bipartite graph, a node cannot be connected to another node in the same partition.

Here, you're going to write a function that returns the nodes from a given partition in a bipartite graph. In this case, the relevant partitions of the Github bipartite graph you'll be working with are 'projects' and 'users'.

Instructions

100 XP
  • Write a function called get_nodes_from_partition() which accepts two arguments - a bipartite graph G and a partition of G - and returns just the nodes from that partition.
    • Iterate over all the nodes of G (not including the metadata) using a for loop.
    • Access the 'bipartite' keyword of the current node's metadata dictionary. If it equals partition, append the current node to the list nodes.
  • Use your get_nodes_from_partition() function together with the len() function to:
    • Print the number of nodes in the 'projects' partition of G.
    • Print the number of nodes in the 'users' partition of G.