เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

แนะนำ repository

ใกล้จะถึงตอนสุดท้ายแล้ว! แบบฝึกหัดนี้จะฝึกการใช้ set difference และนำไปประยุกต์ใช้ในการแนะนำ repository จากผู้ใช้คนที่สองให้กับผู้ใช้คนแรก

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การวิเคราะห์เครือข่ายระดับกลางใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • เขียนฟังก์ชันชื่อ recommend_repositories() ที่รับ argument 3 ตัว ได้แก่ G, from_user และ to_user แล้วคืนค่า repository ที่ from_user มีการเชื่อมต่อ แต่ to_user ไม่มีการเชื่อมต่อ
    • หาชุด repository ที่ from_user เคยมีส่วนร่วม แล้วเก็บไว้เป็น from_repos โดยเริ่มจากการหา neighbors ของ from_user จากนั้นใช้ฟังก์ชัน set() กับผลลัพธ์ที่ได้
    • หาชุด repository ที่ to_user เคยมีส่วนร่วม แล้วเก็บไว้เป็น to_repos
    • ใช้เมธอด .difference() เพื่อคืนค่า repository ที่ from_user มีการเชื่อมต่อ แต่ to_user ไม่มีการเชื่อมต่อ
  • พิมพ์ repository ที่จะแนะนำ จาก '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(____)
แก้ไขและรันโค้ด