开始使用免费开始使用

为您的包添加功能

得益于您之前的工作,您已经有了一个 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)
编辑并运行代码