リポジトリを推薦する
いよいよ終盤です!ここでは集合の差分の使い方を練習し、2人目のユーザーが関与しているリポジトリのうち、1人目のユーザーが貢献すべきものを推薦するタスクに適用します。
この演習はコースの一部です
Python 中級ネットワーク解析
演習の手順
G、from_user、to_userの3つの引数を受け取り、from_userが接続していてto_userが接続していないリポジトリを返すrecommend_repositories()関数を作成してください。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(____)