Dictionaries and Sets Flashcards
(Fill-In) _____ can be thought of as unordered collections in which each value is accessed through its corresponding key.
Dictionaries
(True/False) Dictionaries may contain duplicate keys.
False. Dictionary keys must be unique. However, multiple keys may have the same value.
(Fill-In) Dictionary method _____ returns each key–value pair as a tuple.
items
(True/False) Assigning to a nonexistent dictionary key causes an exception.
False. Assigning to a nonexistent key inserts a new key–value pair. This may be what you intend, or it could be a logic error if you incorrectly specify the key.
(Fill-In) What does an expression of the following form do when the key is in the dictionary?
dictionaryName[key] = value
Answer: It updates the value associated with the key, replacing the original value.
(Fill-In) Dictionary method ____ returns an unordered list of the dictionary’s keys.
keys.
(True/False) A view has its own copy of the corresponding data from the dictionary.
False. A view does not have its own copy of the corresponding data from the dictionary. As the dictionary changes, each view updates dynamically.
(True/False) The == comparison evaluates to True only if both dictionaries have the
same key–value pairs in the same order.
False. The == comparison evaluates to True if both dictionaries have the same
key–value pairs, regardless of their order.
(Fill-In) String method ______ tokenizes a string using the delimiter provided in the method’s string argument.
split.
(True/False) Sets are collections of unique mutable and immutable objects.
False. Sets are collections of unique immutable objects
(Fill-In) You can create a set from another collection of values by using the built-in ______ function
set.
(True/False) Sets may be compared with only the == and != comparison operators.
False. All the comparison operators may be used to compare sets.
(Fill-In) A subset is a(n) _____ subset of another set if all the subset’s elements are in the other set and the other set has more elements.
proper.
(Fill-In) Two sets are _____ if the sets do not have any common elements.
disjoint.
(True/False) Set method pop returns the first element added to the set.
False. Set method pop returns an arbitrary set element.