시작하기무료로 시작하기

가장 인기 있는 포럼을 날짜별로 찾기: I

아주 잘하셨어요! 이제 마지막 두 개의 연습 문제에 도전할 차례인데, 사실상 하나의 긴 연습 문제라고 보시면 됩니다. Python 프로그래밍 실력을 복습하기에 딱 좋아요!

주어진 시간 창에서 "가장 인기 있는 포럼" 자리를 차지한 포럼이 몇 개인지 살펴보겠습니다.

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

Python 중급 네트워크 분석

강의 보기

연습 안내

  • 날짜별로 가장 인기 있는 포럼 목록을 담을 리스트 most_popular_forums를 만드세요.
  • 가장 인기 있는 포럼의 차수 중심성 점수를 담을 리스트 highest_dcs를 만드세요.
  • 새로운 그래프 G_sub를 생성하고, 원래 그래프 G의 노드를 .add_nodes_from() 메서드로 추가하세요.
  • 이전 연습 문제와 동일한 조건을 만족하는 원래 그래프 G의 간선을 G_sub에 추가하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Import necessary modules
from datetime import timedelta
import networkx as nx
import matplotlib.pyplot as plt

# Instantiate a list to hold the list of most popular forums by day: most_popular_forums
most_popular_forums = ____
# Instantiate a list to hold the degree centrality scores of the most popular forums: highest_dcs
highest_dcs = ____
curr_day = dayone  
td = timedelta(days=1)  

while curr_day < lastday:  
    if curr_day.day == 1: 
        print(curr_day) 
    # Instantiate new graph: G_sub
    G_sub = ____
    
    # Add in nodes from original graph G
    ____
    
    # Add in edges from the original graph G that fulfill the criteria
    G_sub.____([(____, ____, ____) for ____, ____, ____ in ____ if d['____'] >= ____ and d['____'] < ____ + ____])
    
    # CODE CONTINUES ON NEXT EXERCISE
    curr_day += td
코드 편집 및 실행