curriculum/challenges/english/blocks/quiz-dictionaries-and-sets/67f412ac59601c4151b763da.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
What is a dictionary?
A data structure that only holds strings and lists.
A data structure that is a collection of key-value pairs that only accept large numbers.
A data structure that only holds a collection of tuples.
A data structure that is a collection of key-value pairs.
Which of the following is the correct syntax for a dictionary?
dictionary = {
<key1: value1>,
<key2: value2>
}
dictionary = {
(key1: value1),
(key2: value2)
}
dictionary = {
[key1: value1],
[key2: value2]
}
dictionary = {
key1: value1,
key2: value2
}
Which of the following is true about dictionaries?
Keys must be at least two characters in length.
Keys must include a special symbol.
Keys must include at least one number.
Keys must be unique.
Which of the following constructors can be used to create a dictionary?
diction()
dic()
dictionary()
dict()
Which of the following is the correct way to access a value from a dictionary?
dictionary<key>
dictionary/key/
dictionary{key}
dictionary[key]
Which of the following is the correct way to update a value in a dictionary?
pizza['name'] >> 'Margherita'
pizza['name'] << 'Margherita'
pizza['name'] == 'Margherita'
pizza['name'] = 'Margherita'
Which of the following methods can be used to retrieve a value associated with a key?
access()
set()
retrieve()
get()
What is a view object?
A special object used to turn strings into dictionaries.
A way to view the content of a dictionary only if the dictionary has two or more key-value pairs.
A special object used to turn lists into dictionaries.
A way to see the content of a dictionary without creating a separate copy of the data.
Which of the following methods returns a view object with all the key-value pairs in the dictionary?
lists()
dictionaries()
collections()
items()
Which of the following methods removes all of the key-value pairs from the dictionary?
empty()
replace()
remove()
clear()
What will be the output for the following code?
products = {
'Laptop': 990,
'Smartphone': 600,
'Tablet': 250,
'Headphones': 70,
}
for product in products.items():
print(product)
<'Laptop', 990>
<'Smartphone', 600>
<'Tablet', 250>
<'Headphones', 70>
'Laptop', 990
'Smartphone', 600
'Tablet', 250
'Headphones', 70
['Laptop', 990]
['Smartphone', 600]
['Tablet', 250]
['Headphones', 70]
('Laptop', 990)
('Smartphone', 600)
('Tablet', 250)
('Headphones', 70)
Which of the following is true about sets?
Sets are mutable and ordered in reverse.
Sets are mutable and ordered.
Sets are immutable and unordered.
Sets are mutable and unordered.
Which of the following is the correct way to create a set?
my_set = (1, 2, 3, 4, 5)
my_set = <1, 2, 3, 4, 5>
my_set = [1, 2, 3, 4, 5]
my_set = {1, 2, 3, 4, 5}
Which of the following functions is used to create an empty set?
create_set()
empty_set()
sets()
set()
What will be output to the terminal?
my_set = {1, 2, 3, 4, 5, 6}
my_set.add(5)
print(my_set)
SyntaxError
RangeError
{1, 2, 3, 4, 5, 5, 6}
{1, 2, 3, 4, 5, 6}
Which of the following methods checks if a set is a subset?
issub()
isset()
subset()
issubset()
Which of the following methods checks if two sets are disjoint?
joint()
isjoint()
disjoint()
isdisjoint()
What does the symmetric difference operator(^) do?
It returns a new set with only the elements that the sets have in common.
It finds the difference between the sets and updates the first set with that result.
It returns a new set with the elements of the first set that are not in the other set.
It returns a new set with the elements that are either in the first or the second set, but not both.
Which of the following built-in modules is used for generating random numbers?
set_random
get_random
rand
random
Which of the following modules is used for working with regular expressions?
regex
reg
r
re