Step: Capstone: put it together

Capstone: put it together

Time to combine everything: sorting with a key, a for loop, f-string formatting, and dict access.

Why it matters: real scripts rarely use one technique in isolation — this is what a typical small data-processing script looks like.

Example: the pieces are all ones you've already used — sort descending with a negated key, then format each row.

Your turn: print orders sorted by total descending, each line as Name: $amount with two decimal places.

Pitfall: to sort descending with key=, negate the key value (-o["total"]) rather than trying to pass a nonexistent reverse= alongside a custom comparator logic — sorted(..., key=..., reverse=True) also works, but negating is shown here since it composes with the numeric key directly.

Setup:
orders = [
    {"customer": "Lee", "total": 42.5},
    {"customer": "Kim", "total": 15.0},
    {"customer": "Diaz", "total": 99.9},
]
Your code:
Expected output:
Diaz: $99.90
Lee: $42.50
Kim: $15.00
Step 18 of 18