Answered step by step
Verified Expert Solution
Question
1 Approved Answer
QUESTION 1 What is the correct structure to create a dictionary of months where each month will be accessed by its month number ( for
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 April is month
: 'January', 'February',... 'December'
; 'January', ; 'February', ; 'December'
: 'January', : 'February', : 'December'
: 'January', : 'February', : 'December'
points
QUESTION
Match the dictionary methods with their descriptions.
get
items
pop
values
A
Pass in the key and the method returns the associated value. If the key is not found, an exception is not raised, and the default value is returned instead.
B
Returns all the values in the dictionary as a sequence.
C
Pass in the key and the method returns the associated value. The keyvalue pair is also removed from the dictionary. If the key is not found, a KeyValue exception is raised.
D
Returns all the keyvalue pairs in the dictionary as a sequence of tuples.
points Extra Credit
QUESTION
In a dictionary, you use an to locate a specific value.
datum
item
key
element
points
QUESTION
A dictionary can include the same value several times but cannot include the same key several times.
True
False
points
QUESTION
What will be displayed after the following code executes?
cities GA: 'Atlanta', NY: 'Albany', CA: 'San Diego'
morecities NY: 'Buffalo', NC: 'Raleigh', OH: 'Columus'
cities morecities
printcitiesNY
Buffalo
Albany
KeyError
NY: 'Albany'
points
QUESTION
If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.
True
False
points
QUESTION
What is the number of the first index in a dictionary?
the size of the dictionary minus one
Dictionaries are not indexed by number.
points
QUESTION
The difference of set and set is a set that contains only the elements that appear in set but do not appear in set
True
False
points
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.
FL: 'Tallahassee'
KeyError
CA: 'San Diego', NY: 'Albany', GA: 'Atlanta'
CA: 'San Diego', NY: 'Albany', GA: 'Atlanta', FL 'Tallahassee'
points
QUESTION
Which of the following does not apply to sets?
The elements are in pairs.
The elements are unordered.
All the elements must be unique; you cannot have two elements with the same value.
The stored elements can be of different data types.
points
QUESTION
In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the operator.
in
included
isin
isnotin
points
QUESTION
What is the value of the variable phones after the following code executes?
phones John : 'Julie' :
phonesJohn
John : 'Julie' :
John : 'Julie' :
John :
This code is invalid.
points
QUESTION
Sets are immutable.
True
False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started