Computers

11th

grade

Image

DICTIONARIES

19
plays

8 questions

Show Answers
See Preview
  • 1. Multiple Choice
    30 seconds
    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) }

  • 2. Multiple Choice
    30 seconds
    1 pt

    Consider this dictionary:


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


    What is the result of this statement:


    d['bar':'baz']

    It raises an exception

    (200, 300)

    200 300

    [200, 300]

  • 3. Multiple Choice
    30 seconds
    1 pt

    Suppose x is defined as follows:

    x = [

    'a',

    'b',

    {

    'foo': 1,

    'bar':

    {

    'x' : 10,

    'y' : 20,

    'z' : 30

    },

    'baz': 3

    },

    'c',

    'd'

    ]

    What is the expression involving x that accesses the value 30?

    x[2]["bar"]["z"]

    x[2]["bar"]

    x["bar"]["z"]

    x[2]["bar"]["z"][3]

  • Answer choices
    Tags
    Answer choices
    Tags

    Explore all questions with a free account

    Already have an account?