Question: Answer the following questions: Write a statement that creates a dictionary containing the following key-value pairs: 'a' : 1 'b' : 2 'c' : 3

  1. Answer the following questions:
  1. Write a statement that creates a dictionary containing the following key-value pairs:

'a' : 1

'b' : 2

'c' : 3

  1. Write a statement that creates an empty dictionary.

  1. Assume the variable dct references a dictionary. Write an if statement that determines whether the key 'James' exists in the dictionary. If so, display the value that is associated with that key. If the key is not in the dictionary, display a message indicating so.

  1. Assume the variable dct references a dictionary. Write an if statement that determines whether the key 'Jim' exists in the dictionary. If so, delete 'Jim' and its associated value.

  1. Answer the following questions:
  1. What will the following code display?

dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3}

print(dct['Tuesday'])

  1. What will the following code display?

dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3}

print(dct.get('Monday', 'Not found'))

  1. What will the following code display?

dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3}

print(dct.get('Friday', 'Not found'))

  1. What will the following code display?

stuff = {'aaa' : 111, 'bbb' : 222, 'ccc' : 333}

print(stuff['bbb'])

  1. How do you delete an element from a dictionary?

  1. How do you determine the number of elements that are stored in a dictionary?

  1. What will the following code display?

dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]}

print(dct[3])

  1. What values will the following code display? (Dont worry about the order in which they will be displayed.)

dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]}

for k in dct:

print(k)

  1. Tuples resemble lists in many ways. However, as an immutable type, the ways in which they can be interacted with are limited. Take the following statements. What will happen if you try to add to the tuple in the manner shown? How can you rewrite the code to achieve the intended result?

Tuple = ()

for i in range (10):

Tuple = Tuple + i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!