Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON Question 1: Dictionaries contain key-value pairs. Values are like a list's indexes. True False Question 2:

PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON PYTHON

Question 1:

Dictionaries contain key-value pairs. Values are like a list's indexes.

True

False

Question 2:

Dictionaries do not consider the key-value pairs to be in any certain 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 the dictionary

Question 6:

What method provides a way to avoid a KeyError message by returning a result when attempting to access keys that may not be present in a dictionary?

items()

values()

has()

get()

Question 7:

What method provides a way to set a default key-value pair when wanting to access a key that may not be present in a dictionary?

items()

default()

has()

setdefault()

Question 8:

What expression would give the same result as the following? 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 on a 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 the keys 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

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions