パッケージに機能を追加する
これまでの作業により、Python パッケージの骨組みはすでにできています。この演習では、単語の使用状況をテキスト分析するために必要な関数を定義していきます。
counter_utils.py ファイルで、パッケージの一部となる 2 つの関数 plot_counter と sum_counters を実装します。パッケージの構成は以下のツリーのとおりです。コーディングは counter_utils.py ファイルで行います。
text_analyzer
├── __init__.py
└── counter_utils.py
この演習はコースの一部です
Pythonで学ぶSoftware Engineeringの原則
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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)