The Tiny Toolbox
At the end of this craft-bench chapter, Hoppy has already practiced function returns and cleaner list work. Now we add one small but very practical idea: Python already comes with some ready-made little tools, so not every common job has to be built from scratch.
Today we only pull out one useful helper: statistics.mean(). The point is not to memorize module names. The point is to build a relaxed habit: when you need a common little move, ask first, “Does Python already have a tool for this? Can I look it up in the docs?”
Sometimes you can just hand a list to a ready-made tool
In a teaching example, this move can stay smaller than the real task. Imagine one tiny helper has already returned a short list of lantern counts. You can hand that returned list straight to the standard-library helper mean() and let it do the averaging step.
import statistics
def gather_lantern_counts():
return [2, 5, 8]
lantern_counts = gather_lantern_counts()
average_count = statistics.mean(lantern_counts)
print("Lantern counts:", lantern_counts)
print("Average count:", average_count)
The point is only the handoff: one step gives you a list, and a ready-made helper summarizes it. Later, in the real starter, you will apply that habit to the prepared score list yourself. Here the example stays tiny on purpose, so you can focus on the action instead of accidentally seeing the whole task solved too early.
The real takeaway is not a module list, but the habit of looking for a tool first
The most important checkpoint idea in this lesson is not “memorize what else lives inside statistics.” It is this: when you meet a common task such as averages, counting, dates, or paths, it is okay to check the docs first and see whether Python already has a built-in helper. Knowing how to look up and use a tool matters more than carrying a long module list in your head.
Keep the prepared collect_scores(raw_scores) call so cleaned_scores still comes from the function return value. This lesson is not about rewriting the cleanup step. It is about connecting that result to a ready-made tool.
Import statistics, or import mean from it directly. Then hand cleaned_scores to that helper to produce average_score.
When you run the code, you should see both the cleaned score list and the average score. That helps you see the flow clearly: a function output can be consumed by the next tool, and the whole pipeline still stays light.
Using one small tool well is enough for today. If you forget the module name later, that is completely fine. Describe the job first, then check the Python docs or search for something like “python mean statistics.” That is a healthy tiny-toolbox habit.
Suggested SolutionExpandCollapse
import statistics
raw_scores = [" 12", "15 ", " 9 ", "18"]
def collect_scores(raw_values):
return [int(raw_value.strip()) for raw_value in raw_values if raw_value.strip()]
cleaned_scores = collect_scores(raw_scores)
average_score = statistics.mean(cleaned_scores)
print("Cleaned scores:", cleaned_scores)
print("Average score:", average_score)Advanced TipsWant more? Click to expandClick to collapse
This lesson intentionally does not keep expanding into other statistics helpers, and it does not compare many more modules. The goal right now is only to show that when a task is common, you do not always need to invent the whole solution yourself. Sometimes the standard library already has a light ready-made part.
That also ties the chapter together nicely: functions can return useful results, lists can be cleaned first, and a tiny helper can consume that result next. At this point, you are starting to build something that feels more like a real little tool instead of a pile of unrelated statements.