Deck 9: Dictionaries and Sets

Full screen (f)
exit full mode
Question
The values of an associative data structure are unordered.
Use Space or
up arrow
down arrow
to flip the card.
Question
The location that an element is stored in and retrieved from in an associative data structure depends on both its key value and its index value.
Question
The dictionary type in Python is an associative data structure.
Question
The dictionary type in Python is of variable length.
Question
A dictionary may be contained within another dictionary.
Question
Dictionaries in Python are

A) mutable
B) immutable
C) neither mutable nor immutable
D) mutable or immutable, depending on the situation
E) none of the above
Question
Which of the following contains the proper Python syntax for defining a dictionary?

A) fruitPrices = ['bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00]
B) fruitPrices = {'bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00}
C) monthlyIncome = [['March', 2000], ['April', 2300], ['May', 1900]]
D) firstFiveInts = {1, 2, 3, 4, 5}
E) None of the above
Question
Which of the following CANNOT be used as a key value in a dictionary?

A) integers
B) strings
C) tuples
D) lists
E) all of the above
Question
Which of the following is NOT valid in Python for dictionary d?

A) d = dict()
B) d['apples'] , for key value 'apples' in d
C) len(d)
D) 'apples' in d
E) del 'apples'
Question
The values stored in a dictionary are assigned/retrieved by use of a corresponding key value. Therefore, dictionaries in Python are an ___________________ data structure.
Question
The location that a given value is stored in a dictionary in Python is determined by its key value. The process of determing the storge location of a value based on the value itself is called __________.
Question
Three example of the types of values that be used as key values of dictionaries in Python are _____________, ________________, and _______________..
Question
Define a dictionary named spanish_days that contains as key values the days of the week ('Sunday', 'Monday', etc), in which each key value has the corresponding name in Spanish ('Domingo','Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado').
Question
Assuming that dictionary spanish_days from the question above has been defined, give an instruction that uses spanish_days to display "The word for Monday in Spanish is Lunes".
Question
Assuming the dictionary spanish_days from the question above has been defined, and that variable day contains one of 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' and 'Sunday'. Give an instructions that displays "The word for english_dayname in Spanish is Spanish_dayname".
Question
A set in Python is a mutable data type, and a frozenset is an immutable type.
Question
The set type provides the usual mathematical opertions on sets (e.g., intersection, union).
Question
As with the dictionary type in Python, the values of a set or frozenset type are unordered.
Question
A set stores only one instance of each value, but keeps track of how many instances of each value have been attempted to be added to the set.
Question
A new empty set is created by use of empty curly braces.
Question
As with sequence types, the in operator is used to determine if a particular value is in given set.
Question
Which of the following is true of sets / frozensets in Python?

A) sets are immutable, and frozensets are mutable
B) sets are mutable and frozensets are both ordered data structures
C) sets are ordered mutable data structures, frozensets are unordered and immutable
D) sets are unordered mutable data structures, frozensets are unordered and immutable
E) none of the above
Question
The following instruction in Python creates
New_datastruc = { }

A) an empty set
B) an empty frozenset
C) an empty dictionary
D) special value None
E) none of the above
Question
Which of the following is NOT valid in Python for set s1 and s2?

A) 'apples' in s1
B) s1 | s2
C) s1 + s2
D) s1 - S2
E) s1 & s2
Question
Which of the following is the correct way to declare a new set?

A) s = new('apples', 'pears', 'bananas')
B) s = new( ('apples', 'pears', bananas') )
C) s = set('apples', 'pears', 'bananas')
D) s = set( ('apples', 'pears', 'bananas') )
E) none of the above
Question
The set type in Python is ______________ , which the frozenset type is __________________.
Question
The set type in Python provides the usual mathematical operations of union, _____________, and ______________.
Question
In order to create an empty set, ___________ is used, not a pair of empty braces, { }.
Question
The proper syntax for creating a set containing the values 'apple', 'pear', and 'banana' is __________________________________.
Question
Define a set named colors that contains the following colors: 'red', 'blue', 'green', 'yellow'.
Question
Assuming that two set of color names have been defined, color1 and color2, give the expression that would produce the names of the colors that are
(a) in either color1 or color2
(b) in both color1 and color2
(c) in color1 but not in color2
(d) in either color1 or color2, but not both
Question
Declare a set named RGB_primarycolors containing the values 'red', 'green', and 'blue', such that the set is immutable.
Question
In the additive (RGB) color model, red and green produce yellow, green and blue produce cyan, and blue and red produce magenta. Define a dictionary named additive_colormixing able to be given any two of these primary colors, and retrieve the resulting color from the combining of the two.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/33
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Dictionaries and Sets
1
The values of an associative data structure are unordered.
True
2
The location that an element is stored in and retrieved from in an associative data structure depends on both its key value and its index value.
False
3
The dictionary type in Python is an associative data structure.
True
4
The dictionary type in Python is of variable length.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
5
A dictionary may be contained within another dictionary.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
6
Dictionaries in Python are

A) mutable
B) immutable
C) neither mutable nor immutable
D) mutable or immutable, depending on the situation
E) none of the above
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following contains the proper Python syntax for defining a dictionary?

A) fruitPrices = ['bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00]
B) fruitPrices = {'bananas' : 1.00, 'apples' : 1.50, 'pears' : 2.00}
C) monthlyIncome = [['March', 2000], ['April', 2300], ['May', 1900]]
D) firstFiveInts = {1, 2, 3, 4, 5}
E) None of the above
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following CANNOT be used as a key value in a dictionary?

A) integers
B) strings
C) tuples
D) lists
E) all of the above
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following is NOT valid in Python for dictionary d?

A) d = dict()
B) d['apples'] , for key value 'apples' in d
C) len(d)
D) 'apples' in d
E) del 'apples'
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
10
The values stored in a dictionary are assigned/retrieved by use of a corresponding key value. Therefore, dictionaries in Python are an ___________________ data structure.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
11
The location that a given value is stored in a dictionary in Python is determined by its key value. The process of determing the storge location of a value based on the value itself is called __________.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
12
Three example of the types of values that be used as key values of dictionaries in Python are _____________, ________________, and _______________..
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
13
Define a dictionary named spanish_days that contains as key values the days of the week ('Sunday', 'Monday', etc), in which each key value has the corresponding name in Spanish ('Domingo','Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado').
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
14
Assuming that dictionary spanish_days from the question above has been defined, give an instruction that uses spanish_days to display "The word for Monday in Spanish is Lunes".
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
15
Assuming the dictionary spanish_days from the question above has been defined, and that variable day contains one of 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' and 'Sunday'. Give an instructions that displays "The word for english_dayname in Spanish is Spanish_dayname".
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
16
A set in Python is a mutable data type, and a frozenset is an immutable type.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
17
The set type provides the usual mathematical opertions on sets (e.g., intersection, union).
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
18
As with the dictionary type in Python, the values of a set or frozenset type are unordered.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
19
A set stores only one instance of each value, but keeps track of how many instances of each value have been attempted to be added to the set.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
20
A new empty set is created by use of empty curly braces.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
21
As with sequence types, the in operator is used to determine if a particular value is in given set.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following is true of sets / frozensets in Python?

A) sets are immutable, and frozensets are mutable
B) sets are mutable and frozensets are both ordered data structures
C) sets are ordered mutable data structures, frozensets are unordered and immutable
D) sets are unordered mutable data structures, frozensets are unordered and immutable
E) none of the above
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
23
The following instruction in Python creates
New_datastruc = { }

A) an empty set
B) an empty frozenset
C) an empty dictionary
D) special value None
E) none of the above
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following is NOT valid in Python for set s1 and s2?

A) 'apples' in s1
B) s1 | s2
C) s1 + s2
D) s1 - S2
E) s1 & s2
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following is the correct way to declare a new set?

A) s = new('apples', 'pears', 'bananas')
B) s = new( ('apples', 'pears', bananas') )
C) s = set('apples', 'pears', 'bananas')
D) s = set( ('apples', 'pears', 'bananas') )
E) none of the above
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
26
The set type in Python is ______________ , which the frozenset type is __________________.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
27
The set type in Python provides the usual mathematical operations of union, _____________, and ______________.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
28
In order to create an empty set, ___________ is used, not a pair of empty braces, { }.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
29
The proper syntax for creating a set containing the values 'apple', 'pear', and 'banana' is __________________________________.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
30
Define a set named colors that contains the following colors: 'red', 'blue', 'green', 'yellow'.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
31
Assuming that two set of color names have been defined, color1 and color2, give the expression that would produce the names of the colors that are
(a) in either color1 or color2
(b) in both color1 and color2
(c) in color1 but not in color2
(d) in either color1 or color2, but not both
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
32
Declare a set named RGB_primarycolors containing the values 'red', 'green', and 'blue', such that the set is immutable.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
33
In the additive (RGB) color model, red and green produce yellow, green and blue produce cyan, and blue and red produce magenta. Define a dictionary named additive_colormixing able to be given any two of these primary colors, and retrieve the resulting color from the combining of the two.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 33 flashcards in this deck.