Python 3220 Chapter 9
What is the number of the first index in a dictionary? the size of the dictionary minus one 1 Dictionaries are not indexed by number. 0
Dictionaries are not indexed by number.
A set comprehension is written just like a list comprehension, except that a set comprehension is enclosed in angled brackets (<>), and a list comprehension is enclosed in square brackets ([]). True or False
False
Sets are created using curly braces { }. True or False
False
The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs. True or False
False
The union of two sets is a set that contains only the elements that appear in both sets. True or False
False
What does the get method do if the specified key is NOT found in the dictionary? It does nothing. It returns a default value. It throws an exception. You cannot use the get method to specify a key.
It returns a default value.
Which of the following does NOT apply to sets? All the elements must be unique; you cannot have two elements with the same value. The elements are in pairs. The stored elements can be of different data types. The elements are unordered.
The elements are in pairs.
A dictionary can include the same value several times but cannot include the same key several times. True or False
True
If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised. True or False
True
The difference of set1 and set2 is a set that contains only the elements that appear in set1 but do not appear in set2. True or False
True
The issubset() method can be used to determine whether set1 is a subset of set2. True or False
True
The set remove and discard methods behave differently only when a specified item is not found in the set. True or False
True
In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the ________ operator. isin in included isnotin
in
Which method would you use to get all the elements in a dictionary returned as a list of tuples? pop keys items list
items
Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary? popitem items pop list
pop
What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)? { 1, 2,... 12 : 'January', 'February',... 'December'} { 1 ; 'January', 2 ; 'February', ... 12 ; 'December'} [ '1' : 'January', '2' : 'February', ... '12' : 'December' ] { 1 : 'January', 2 : 'February', ... 12 : 'December' }
{ 1 : 'January', 2 : 'February', ... 12 : 'December' }
What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'} ['CA': 'Sacramento'] {'CA': 'Sacramento'} {'NY': 'Albany', 'GA': 'Atlanta'}
{'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}
What will be displayed after the following code executes? (Note: the order of the display of entries in a dictionary are not in a specific order.) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} {'FL': 'Tallahassee'} KeyError {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'}
{'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}
What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = '5556666' {'John' : '5555555', 'Julie' : '5557777'} {'John' : '5556666'} This code is invalid. {'John' : '5556666', 'Julie' : '5557777'}
{'John' : '5556666', 'Julie' : '5557777'}
What values will d2 contain after the following code executes? d = {1: 10, 2: 20, 3: 30} d2 = {k:v for k,v in d.items()} {1: 1, 2: 2, 3: 3} {10: 1, 20: 2, 30: 3} {10: 10, 20: 20, 30: 30} {1: 10, 2: 20, 3: 30}
{1: 10, 2: 20, 3: 30}