Assessment: Python Dictionaries

May 8, 2014 • Christian Jacobs

I have written two multiple choice questions (MCQs) about Python dictionaries. Some of the key concepts associated with Python dictionaries are given in the excellent concept map by Jeremiah Lant.

  1. Which of the following is not a valid dictionary key:
    • "_hello_world_"
    • -1
    • ("alice", "bob")
    • ["alice"]
  2. Consider a dictionary defined by: d = {"A":8, "B":5}. The statement d["A"] = "Hello" will:
    • Add a new key-value pair "A":"Hello" to the dictionary.
    • Overwrite the value already associated with "A" such that the key-value pair "A":8 becomes "A":"Hello"
    • Merge the value already associated with "A" with the value "Hello" to form a list of values, such that the key-value pair "A":8 becomes "A":[8, "Hello"].
    • Cause a TypeError.

Any feedback would be greatly appreciated.