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.
This exercise is part of the course
Intermediate Network Analysis in Python
Exercise instructions
- Write a function called
recommend_repositories()
that accepts 3 arguments -G
,from_user
, andto_user
- and returns the repositories that thefrom_user
is connected to that theto_user
is not connected to.- Get the set of repositories the
from_user
has contributed to and store it asfrom_repos
. To do this, first obtain the neighbors offrom_user
and use theset()
function on this. - Get the set of repositories the
to_user
has contributed to and store it asto_repos
. - Using the
.difference()
method, return the repositories that thefrom_user
is connected to that theto_user
is not connected to.
- Get the set of repositories the
- Print the repositories to be recommended from
'u7909'
to'u2148'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
def ____:
# Get the set of repositories that from_user has contributed to
from_repos = ____
# Get the set of repositories that to_user has contributed to
to_repos = ____
# Identify repositories that the from_user is connected to that the to_user is not connected to
return ____.____(____)
# Print the repositories to be recommended
print(____)