Embercode
✕
Dicts and SetsQuick quiz

Iteration and counts

8 questions. Covers Multisets and counted dicts in Python.

Questions 1 to 5 of 8

  1. 1. Which statement about the order in which a dict loop visits its keys is correct?
  2. 2. A for loop walks over scores and calls del scores[name] inside the loop. What happens?
  3. 3. A counted dict (a multiset) holds {3: 2, 5: 3, 9: 1}. How many items does the bag hold in total, and what does len(bag) return?
  4. 4. Which statement about changing a value inside a for k in bag: loop is correct?
  5. 5. bag[x] = bag[x] + 1 is safe when x is not yet a key, because the dict treats a missing value as 0.

5 question(s) left on this page.