Answered step by step
Verified Expert Solution
Link Copied!

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 1
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)?
{1,2,...12 : 'January', 'February',... 'December' }
{1 ; 'January', 2 ; 'February', ...12 ; 'December'}
{1 : 'January', 2 : 'February', ...12 : 'December' }
['1' : 'January', '2' : 'February', ...'12' : 'December' ]
10 points
QUESTION 2
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 key-value pair is also removed from the dictionary. If the key is not found, a KeyValue exception is raised.
D.
Returns all the key-value pairs in the dictionary as a sequence of tuples.
10 points (Extra Credit)
QUESTION 3
In a dictionary, you use a(n)________ to locate a specific value.
datum
item
key
element
10 points
QUESTION 4
A dictionary can include the same value several times but cannot include the same key several times.
True
False
5 points
QUESTION 5
What will be displayed after the following code executes?
cities ={'GA': 'Atlanta', 'NY': 'Albany', 'CA': 'San Diego'}
more_cities ={'NY': 'Buffalo', 'NC': 'Raleigh', 'OH': 'Columus'}
cities |= more_cities
print(cities['NY'])
Buffalo
Albany
KeyError
{'NY': 'Albany'}
10 points
QUESTION 6
If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.
True
False
5 points
QUESTION 7
What is the number of the first index in a dictionary?
0
1
the size of the dictionary minus one
Dictionaries are not indexed by number.
10 points
QUESTION 8
The difference of set1 and set2 is a set that contains only the elements that appear in set1 but do not appear in set2.
True
False
5 points
QUESTION 9
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'}
10 points
QUESTION 10
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.
10 points
QUESTION 11
In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the ________ operator.
in
included
isin
isnotin
10 points
QUESTION 12
What is the value of the variable phones after the following code executes?
phones ={'John' : '5555555', 'Julie' : '5557777'}
phones['John']='5556666'
{'John' : '5555555', 'Julie' : '5557777'}
{'John' : '5556666', 'Julie' : '5557777'}
{'John' : '5556666'}
This code is invalid.
10 points
QUESTION 13
Sets are immutable.
True
False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions