Syllabus Lesson 15 of 141 · Rules of the duel
Rules of the duel

Being contrary loses

Why it matters After one trap, it is tempting to treat every obvious answer as wrong. That is just a new default, and it is a worse one.

A shop page shows the three cheapest products in a category. Categories hold about 50 products. The team that owns this code reads it far more often than the computer runs it, so they keep a simplicity rule.

Read the rules, then pick the simplest thing that meets them.

Your turn

Write cheapest_three(products): return up to three product dicts ({"name", "price"}) with the lowest prices, cheapest first; equal prices go in alphabetical order of name. Rule: your whole code may have at most 60 syntax nodes (code_size). Lists hold about 50 products.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.