Chapter 2 · 6 levels

Lists, dictionaries and loops

Hold many values at once, look things up by key, and repeat work with loops and comprehensions, all on Harbor & Pine orders and stock.

Start

One price is a variable. A whole cart of prices is a list. A stock sheet where every product name maps to a count is a dictionary. And going through every order to add something up is a loop.

These three ideas are the foundation of pandas, the library you’ll use from chapter 4 onwards. A pandas column behaves a lot like a list, and a row behaves a lot like a dictionary. Learning them in plain Python first makes pandas feel natural instead of magical.

In this chapter you’ll slice a week of order counts, total a cart, update the stock sheet after a delivery, count orders by sales channel, and filter products with a single readable line. The boss level hands you a small batch of raw orders and asks for revenue by channel, which is exactly the kind of question you’ll answer with pandas later, done by hand.

Levels

  1. Slice a week of orders

    from Megan Collins, Head of Sales

    lists, indexing, slicing, len sum max

    Code Difficulty 1 of 5 Not started

  2. Total a cart with a loop

    from Jennifer Castillo, Support Team Lead

    for loop, accumulator, zip

    Code Difficulty 2 of 5 Not started

  3. Update the stock sheet

    from Debra Marshall, Warehouse Manager

    dictionaries, keys values, get, update

    Code Difficulty 2 of 5 Not started

  4. Count orders by channel

    from Andrew Ramos, Marketing Manager

    dictionaries, counting, get, for loop

    Code Difficulty 2 of 5 Not started

  5. Filter products in one line

    from Thomas Whitaker, Head of Merchandising

    list comprehension, filtering, dictionaries

    Code Difficulty 2 of 5 Not started

  6. Boss: revenue by channel, by hand

    from Megan Collins, Head of Sales

    list comprehension, dictionaries, nested data, accumulator

    Boss · 3 steps Difficulty 3 of 5 Not started