시작하기무료로 시작하기

리포지터리 추천하기

거의 다 왔어요! 여기서는 집합의 차집합을 연습하고, 이를 활용해 첫 번째 사용자가 기여하면 좋을 두 번째 사용자의 리포지터리를 추천해 볼 거예요.

이 연습은 강의의 일부입니다

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(____)
코드 편집 및 실행