Week 9 Flashcards
You would typically use a for loop to iterate over the elements in a set.
True
Sets are immutable.
False
Sets are created using curly braces { }.
False
The set remove and discard methods behave differently only when a specified item is not found in the set.
True
A dictionary can include the same value several times but cannot include the same key several times.
True
The union of two sets is a set that contains only the elements that appear in both sets.
False
The difference of set1 and aet2 is a set that contains only the elements that appear in set1 but do not appear in set2.
True
The elements in a dictionary are stored in ascending order, by the keys of the key-value pairs.
False
If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.
True
The issubset() method can be used to determine whether set1 is a subset of set2.
True
In a dictionary, you use a(n) __________ to locate a specific value.
a. datum
b. element
c. item
d. key
d. key
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)?
a. { 1 ; ‘January’, 2 ; ‘February’, … 12 ; ‘December’}
b. { 1 : ‘January’, 2 : ‘February’, … 12 : ‘December’ }
c. [ ‘1’ : ‘January’, ‘2’ : ‘February’, … ‘12’ : ‘December’ ]
d. { 1, 2,… 12 : ‘January’, ‘February’,… ‘December’ }
b. { 1 : ‘January’, 2 : ‘February’, … 12 : ‘December’ }
What will be the result of the following code?
ages = {‘Aaron’ : 6, ‘Kelly’ : 3, ‘Abigail’ : 1 }
value = ages[‘Brianna’]
a. False
b. -1
c. 0
d. KeyError
d. KeyError
What is the number of the first index in a dictionary?
a. 0
b. 1
c. the size of the dictionary minus one
d. Dictionaries are not indexed by number.
d. Dictionaries are not indexed by number.
What is the value of the variable phones after the following code executes?
phones = {‘John’ : ‘5555555’, ‘Julie’ : ‘5557777’}
phones[‘John’] = 5556666’
a. {‘John’ : ‘5555555’, ‘Julie’ : ‘5557777’}
b. {‘John’ : ‘5556666’, ‘Julie’ : ‘5557777’}
c. {‘John’ : ‘5556666’}
d. This code is invalid.
b. {‘John’ : ‘5556666’, ‘Julie’ : ‘5557777’}