始める無料で始める

リポジトリを推薦する

いよいよ終盤です!ここでは集合の差分の使い方を練習し、2人目のユーザーが関与しているリポジトリのうち、1人目のユーザーが貢献すべきものを推薦するタスクに適用します。

この演習はコースの一部です

Python 中級ネットワーク解析

コースを見る

演習の手順

  • Gfrom_userto_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(____)
コードを編集して実行