Skip to the content

Project: grocery list

Python · Unit 5: Lists

Your grocery list is two lists: items[i] and prices[i] talk about the same product, because the same index ties them together.

With enumerate you walk one and read the other with the index.

items = ["bread", "milk"]
prices = [3, 4]
for i, p in enumerate(prices):
    print(items[i], p)

Prints

bread 3
milk 4

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Complete the code

    Complete it to print the items that cost less than 10.

  2. 2. Write the code

    Write total(prices, counts), which returns what you pay if you take counts[i] of each product at prices[i] each.

  3. 3. Write the code

    Write priciest(items, prices), which returns the name of the most expensive product. The lists never come in empty.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →