Search Header Logo

OOB Python Dictionaries_Q2

Authored by Noorulayin shainsha

Computers

University

Used 2+ times

OOB Python Dictionaries_Q2
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

5 questions

Show all answers

1.

MULTIPLE SELECT QUESTION

1 min • 1 pt

Which of the following are true of Python dictionaries:

Dictionaries can be nested to any depth.

Dictionaries are accessed by key.

All the keys in a dictionary must be of the same type.

Dictionaries are mutable.

A dictionary can contain any object type except another dictionary.

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which of the following is not a valid way to define this dictionary in Python:

d = dict([

('foo', 100),

('bar', 200),

('baz', 300)

])

d = {}

d['foo'] = 100

d['bar'] = 200

d['baz'] = 300

d = dict(foo=100, bar=200, baz=300)

d = {'foo': 100, 'bar': 200, 'baz': 300}

d = { ('foo', 100), ('bar', 200), ('baz', 300) }

3.

MULTIPLE SELECT QUESTION

1 min • 1 pt

Which of the following could be a valid dictionary key:

(3+2j)

('foo', 'bar')

dict(foo=1, bar=2)

'foo'

['foo', 'bar']

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

dict_items([('color'), ('fruit'), ('pet')])

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Consider the following statement:


If you just need to work with the keys of a dictionary, then you can use .keys(), which is a method that returns a new view object containing the dictionary’s keys.


Is this statement True or False?

False

True

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?