Deck 9: Dictionaries and Sets

Full screen (f)
exit full mode
Question
You would typically use a for loop to iterate over the elements in a set.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

A) list
B) items
C) pop
D) popitem
Question
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
Question
Sets are immutable.
Question
Sets are created using curly braces { }.
Question
Which would you use to get the number of elements in a dictionary?

A) size
B) length
C) len
D) sizeof
Question
If you try to retrieve a value from a dictionary using a nonexistent key,a KeyError exception is raised.
Question
The elements in a dictionary are stored in ascending order,by the keys of the key-value pairs.
Question
Which method would you use to get all the elements in a dictionary returned as a list of tuples?

A) list
B) items
C) pop
D) keys
Question
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' }
Question
Which would you use to delete an existing key-value pair from a dictionary?

A) del
B) remove
C) delete
D) unpair
Question
The difference of set1 and aet2 is a set that contains only the elements that appear in set1 but do not appear in set2.
Question
A dictionary can include the same value several times but cannot include the same key several times.
Question
The issubset()method can be used to determine whether set1 is a subset of set2.
Question
In a dictionary,you use a(n)__________ to locate a specific value.

A) datum
B) element
C) item
D) key
Question
Which method can be used to add a group of elements to a set?

A) add
B) addgroup
C) update
D) addset
Question
The union of two sets is a set that contains only the elements that appear in both sets.
Question
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.
Question
The set remove and discard methods behave differently only when a specified item is not found in the set.
Question
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.
Question
To add a single item to a set,you can use the set __________ method.
Question
What does the get method do if the specified key is not found in the dictionary?

A) It throws an exception.
B) It does nothing.
C) It returns a default value.
D) You cannot use the get method to specify a key.
Question
The __________ method clears the contents of a dictionary.
Question
The built-in function,__________,returns the number of items in a set.
Question
To write an object to a file,you use the __________ function of the __________ module.
Question
Each element in a(n)__________ has two parts: a key and a value.
Question
The elements in a dictionary are not stored in a specific order.
Therefore,a dictionary is not a(n)___________.
Question
Each element in a dictionary view is a __________.
Question
The __________ method returns a value associated with a specific key and,if found,removes that key-value pair from the dictionary.
Question
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.)
<strong>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.)  </strong> A) {'FL': 'Tallahassee'} B) KeyError C) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'} D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} <div style=padding-top: 35px>

A) {'FL': 'Tallahassee'}
B) KeyError
C) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'}
D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}
Question
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.)
<strong>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.)  </strong> A) {'FL': 'Tallahassee'} B) KeyError C) {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'} D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'} <div style=padding-top: 35px>

A) {'FL': 'Tallahassee'}
B) KeyError
C) {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'}
D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}
Question
A(n)__________ is an object that holds multiple unique items of data in an unordered manner.
Question
In order to avoid KeyError exceptions,you can check whether a key is in the dictionary using the __________ operator.

A) included
B) in
C) isnotin
D) isin
Question
What is the process used to convert an object to a stream of bytes that can be saved in a file?

A) pickling
B) streaming
C) writing
D) dumping
Question
The __________ method returns all of a dictionary's keys as a dictionary view.
Question
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.)
<strong>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.)  </strong> A) {'CA': 'Sacramento'} B) ['CA': 'Sacramento'] C) {'NY': 'Albany', 'GA': 'Atlanta'} D) {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'} <div style=padding-top: 35px>

A) {'CA': 'Sacramento'}
B) ['CA': 'Sacramento']
C) {'NY': 'Albany', 'GA': 'Atlanta'}
D) {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}
Question
To determine whether or not a key is included in a dictionary,or if an element is included in a set,you can use the ___________ operator.
Question
The __________ of two sets is a set that contains all the elements of both sets.
Question
Which of the following does not apply to sets?

A) The stored elements can be of different data types.
B) All the elements must be unique; you cannot have two elements with the same value.
C) The elements are unordered.
D) The elements are in pairs.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/39
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Dictionaries and Sets
1
You would typically use a for loop to iterate over the elements in a set.
True
2
Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

A) list
B) items
C) pop
D) popitem
C
3
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
4
Sets are immutable.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
5
Sets are created using curly braces { }.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
6
Which would you use to get the number of elements in a dictionary?

A) size
B) length
C) len
D) sizeof
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
7
If you try to retrieve a value from a dictionary using a nonexistent key,a KeyError exception is raised.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
8
The elements in a dictionary are stored in ascending order,by the keys of the key-value pairs.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
9
Which method would you use to get all the elements in a dictionary returned as a list of tuples?

A) list
B) items
C) pop
D) keys
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
10
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' }
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
11
Which would you use to delete an existing key-value pair from a dictionary?

A) del
B) remove
C) delete
D) unpair
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
12
The difference of set1 and aet2 is a set that contains only the elements that appear in set1 but do not appear in set2.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
13
A dictionary can include the same value several times but cannot include the same key several times.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
14
The issubset()method can be used to determine whether set1 is a subset of set2.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
15
In a dictionary,you use a(n)__________ to locate a specific value.

A) datum
B) element
C) item
D) key
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
16
Which method can be used to add a group of elements to a set?

A) add
B) addgroup
C) update
D) addset
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
17
The union of two sets is a set that contains only the elements that appear in both sets.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
18
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.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
19
The set remove and discard methods behave differently only when a specified item is not found in the set.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
20
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.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
21
To add a single item to a set,you can use the set __________ method.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
22
What does the get method do if the specified key is not found in the dictionary?

A) It throws an exception.
B) It does nothing.
C) It returns a default value.
D) You cannot use the get method to specify a key.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
23
The __________ method clears the contents of a dictionary.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
24
The built-in function,__________,returns the number of items in a set.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
25
To write an object to a file,you use the __________ function of the __________ module.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
26
Each element in a(n)__________ has two parts: a key and a value.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
27
The elements in a dictionary are not stored in a specific order.
Therefore,a dictionary is not a(n)___________.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
28
Each element in a dictionary view is a __________.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
29
The __________ method returns a value associated with a specific key and,if found,removes that key-value pair from the dictionary.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
30
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.)
<strong>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.)  </strong> A) {'FL': 'Tallahassee'} B) KeyError C) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'} D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

A) {'FL': 'Tallahassee'}
B) KeyError
C) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta', 'FL' 'Tallahassee'}
D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
31
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.)
<strong>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.)  </strong> A) {'FL': 'Tallahassee'} B) KeyError C) {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'} D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}

A) {'FL': 'Tallahassee'}
B) KeyError
C) {'GA': 'Atlanta', 'FL': 'Tallahassee', 'NY': 'Albany', 'CA': 'San Diego'}
D) {'CA': 'San Diego', 'NY': 'Albany', 'GA': 'Atlanta'}
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
32
A(n)__________ is an object that holds multiple unique items of data in an unordered manner.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
33
In order to avoid KeyError exceptions,you can check whether a key is in the dictionary using the __________ operator.

A) included
B) in
C) isnotin
D) isin
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
34
What is the process used to convert an object to a stream of bytes that can be saved in a file?

A) pickling
B) streaming
C) writing
D) dumping
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
35
The __________ method returns all of a dictionary's keys as a dictionary view.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
36
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.)
<strong>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.)  </strong> A) {'CA': 'Sacramento'} B) ['CA': 'Sacramento'] C) {'NY': 'Albany', 'GA': 'Atlanta'} D) {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}

A) {'CA': 'Sacramento'}
B) ['CA': 'Sacramento']
C) {'NY': 'Albany', 'GA': 'Atlanta'}
D) {'CA': 'Sacramento', 'NY': 'Albany', 'GA': 'Atlanta'}
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
37
To determine whether or not a key is included in a dictionary,or if an element is included in a set,you can use the ___________ operator.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
38
The __________ of two sets is a set that contains all the elements of both sets.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following does not apply to sets?

A) The stored elements can be of different data types.
B) All the elements must be unique; you cannot have two elements with the same value.
C) The elements are unordered.
D) The elements are in pairs.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 39 flashcards in this deck.