Computer Science I / Simple Modelling with Code
Practice question · Sort into groups

Choosing a fitting data representation is half the battle. Sort each quantity by the type that best models it.

Groups: A single number · A list · A dictionary

Hints
  1. A single value is one number; ordered many-values suit a list; keyed lookups suit a dictionary.
  2. A phone book and a stock lookup are both keyed by a meaningful name or id.
Show the answer

A single number: A person's age, The total price of the cart

A list: The items in a shopping cart, in order

A dictionary: A phone book from names to numbers

Why

Ages and totals are single numbers; a cart's items and a class's scores are ordered lists; a phone book and id-keyed stock are dictionaries. Matching each quantity to a fitting representation is the modelling step that makes the later algorithm easy rather than painful.

Read the lesson: Simple Modelling with Code →

Practise Simple Modelling with Code

The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Simple Modelling with Code