開始使用免費開始

為你的套件加入功能

多虧你之前的工作,你已經有一個 Python 套件的骨架了。這個練習中,你要定義進行文字分析(字詞使用情形)所需的函式。

counter_utils.py 檔案中,你會撰寫 2 個要納入套件的函式:plot_countersum_counters。套件的結構如下方樹狀圖所示。在本練習需要撰寫程式碼的部分,你都會在 counter_utils.py 檔案中進行。

text_analyzer
├── __init__.py
└── counter_utils.py

本練習屬於課程

Python 的軟體工程原則

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import needed functionality
from collections import Counter

def plot_counter(counter, n_most_common=5):
  # Subset the n_most_common items from the input counter
  top_items = ____.most_common(____)
  # Plot `top_items`
  plot_counter_most_common(top_items)
編輯並執行程式碼