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.
- Which of the following is not a valid dictionary key:
"_hello_world_"-1("alice", "bob")["alice"]
- Consider a dictionary defined by:
d = {"A":8, "B":5}. The statementd["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":8becomes"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":8becomes"A":[8, "Hello"]. - Cause a TypeError.
- Add a new key-value pair
Any feedback would be greatly appreciated.