1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Network Analysis in Python

Connected

Exercise

Recommend repositories

You're close to the end! Here, the task is to practice using set differences, and you'll apply it to recommending repositories from a second user that the first user should contribute to.

Instructions

100 XP
  • Write a function called recommend_repositories() that accepts 3 arguments - G, from_user, and to_user - and returns the repositories that the from_user is connected to that the to_user is not connected to.
    • Get the set of repositories the from_user has contributed to and store it as from_repos. To do this, first obtain the neighbors of from_user and use the set() function on this.
    • Get the set of repositories the to_user has contributed to and store it as to_repos.
    • Using the .difference() method, return the repositories that the from_user is connected to that the to_user is not connected to.
  • Print the repositories to be recommended from 'u7909' to 'u2148'.