Question
PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHONPYTHON Question 1: Dictionaries contain key-value pairs. Values are like a list'sindexes. True False Question 2: Dictionaries do
PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHONPYTHON
Question 1:
Dictionaries contain key-value pairs. Values are like a list'sindexes.
True | |
False |
Question 2:
Dictionaries do not consider the key-value pairs to be in anycertain order.
True | |
False |
Question 3:
What is the syntax for writing a dictionary in Python?
[ key : value ] | |
( key, value ) | |
{ value : key } | |
{ key : value } |
Question 4:
When it comes to being able to add, remove, or change values,dictionaries are _____
unchangeable | |
molten | |
mutable | |
immutable |
Question 5:
Given this dictionary: user{'name' : 'Bob', 'username' : 'bob42'}
What happens when you try to access the dictionary like this:user['age']
A KeyError message is displayed | |
The user is prompted to enter Bob's age | |
Bob's age is displayed | |
A default value is set because there is no 'age' key in thedictionary |
Question 6:
What method provides a way to avoid a KeyError message byreturning a result when attempting to access keys that may not bepresent in a dictionary?
items() | |
values() | |
has() | |
get() |
Question 7:
What method provides a way to set a default key-value pair whenwanting to access a key that may not be present in adictionary?
items() | |
default() | |
has() | |
setdefault() |
Question 8:
What expression would give the same result as thefollowing?
if 'age' not in user:
user['age'] = 'unknown'
user.setdefault('age', 'unknown') | |
user.add('age', 'unknown') | |
if get('age') is False set to 'unknown' | |
user = { 'age' : 'unknown' } |
Question 9:
What module and function can be used to "pretty print"dictionary values?
pprint.print() | |
pprint.pprint() | |
pretty.print() | |
print.pprint() |
Question 10:
What type of data does the method items() return when called ona dictionary?
A list of the key and value | |
A list of the only the values | |
A list like dict_keys with the keys | |
A collection of tuples consisting of key and value pairs |
Question 11:
Given this dictionary: user{'name' : 'Bob', 'username' : 'bob42'}
What structure will allow us to loop through and access both thekeys and values in the dictionary?
for v in user.keys() | |
for k, v in user.items(): | |
for 'name' in user: | |
if v in user: |
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