Practice question · Select all that apply
Select every statement that is true of lists and dictionaries as the lesson describes them.
Hints
- Two options describe a dictionary as if it were a list, or miscount a list's indices.
- A dictionary uses keys, not positions; a length-4 list stops at index 3.
Show the answer
- A. Sets do not allow duplicate elements.
- B. Indexing starts at zero, so the final position of a four-element list is 3.
- E. Membership testing is faster in a set than in a list.
Why
Lists are ordered and 0-indexed, so the last of n elements is at n minus 1; dictionaries are keyed by meaningful keys, not positions. Option 2 confuses a dictionary with a list, and option 4 makes the off-by-one error at the boundary.
Practise Basic Data Collections
The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Basic Data Collections
- A list preserves order and allows duplicates; a set does neither and can test membership far faster. Why does…
- For a list of length 4 (valid indices 0 through 3), sort each index by whether accessing it is valid.
- A list stores elements by sequential position, whereas a dictionary associates values with unique keys. What…