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:
Your code:Expected output:
Step 18 of 18