WeCodeAcademy

Step 4: Best sellers and share of revenue

Which products matter most? Use collections.Counter to total units per product (its most_common method sorts for you), and a defaultdict(float) to total revenue. Then compute each top product's share of all revenue with the % format.

Examplepython
Open in editor »

Units and revenue tell different stories: the cheap pen sells the most units but headphones and backpacks earn more per item. A good analysis reports both. The last line groups revenue by month using the first 7 characters of the date (2026-01).

Your turn: write the code

Use Counter to count how often each word appears in the text, and print the two most common words as a list of tuples.

Quick check

What does Counter.most_common(3) return?

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.