Shared batch lists created by a dictionary default

A workshop records batch sizes, in parts, for morning and evening production. Each list entry represents one batch. The Python method dict.fromkeys(keys, value) creates a dictionary that stores the same supplied value under every key; it does not copy that value.


Python
batches = dict.fromkeys(("morning", "evening"), [])
saved = batches["morning"]
batches["morning"].append(3)
batches["evening"].extend([5, 7])
batches["morning"] = [11]
batches["morning"].append(13)
saved.remove(5)


Here, append adds one entry, extend adds each entry from the supplied list, and remove deletes the first matching entry. After all statements execute, determine the total parts in the morning list, the total parts in the evening list, and the number of batches in saved. Enter exact integers in the indicated units.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Mutable vs Immutable Questions: