WeCodeAcademy

Step 7: Package it as a function

Finally, wrap the analysis in a function that returns the headline numbers as a dictionary, so it can be reused on next quarter's file or tested. The report prints the best region and best product.

Examplepython
Open in editor »

You have done a full analysis: question, load, clean, summarise, rank, report, cross-check with SQL and package. Where next: read the CSV from a real file with open(), draw a chart (in the browser with JavaScript or on your computer with a library such as matplotlib), and schedule the script to run every month.

Your turn: write the code

Write best(totals) that takes a dictionary of totals and returns the key with the largest value. Print best({"a": 3, "b": 9, "c": 5}).

Quick check

Why wrap the analysis in a function?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.