パッケージに機能を追加する
前の演習のおかげで、Python パッケージの骨格がすでに完成しています。この演習では、単語の使用状況をテキスト分析するために必要な関数を定義します。
counter_utils.py ファイルに、パッケージの一部となる2つの関数 plot_counter と sum_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)