推荐仓库
就快结束了!本题将练习集合差集的用法,并把它应用到推荐第二位用户的仓库,让第一位用户去参与贡献。
本练习是课程的一部分
Python 网络分析中级
练习说明
- 编写一个名为
recommend_repositories()的函数,接收 3 个参数G、from_user和to_user,返回这样一组仓库:from_user已关联、而to_user未关联的仓库。- 获取
from_user参与贡献过的仓库集合,存为from_repos。为此,先获取from_user的邻居,然后对其使用set()。 - 获取
to_user参与贡献过的仓库集合,存为to_repos。 - 使用
.difference()方法,返回from_user已关联、而to_user未关联的仓库。
- 获取
- 打印需要从
'u7909'推荐给'u2148'的仓库。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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(____)