Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

Would Eq. (2.10) hold true in the elastic range? Explain.

Answered: 1 week ago

Question

=+b) Test an appropriate hypothesis and state your conclusion.

Answered: 1 week ago