wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

COMPUTER DICTIONARY

Total questions: 22

Worksheet time: 12mins

Name
Class
Date
1.

You have the following dictionary definition:


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


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

2.

Which method will remove an element the Dictionary data type?

a)

.pop()

b)

.discard()

c)

.remove()

3.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

4.

Items are accessed by their position in a dictionary

a)

True

b)

False

5.

_________________ method will not only delete the item from dictionary, but also return the deleted value.

a)

del ( )

b)

pop( )

c)

Clear( )

6.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

7.

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)

a)

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

b)

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

c)

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

d)

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

8.

What is the output of the following code

dict1 = {"key1":1, "key2":2}

dict2 = {"key2":2, "key1":1}

print(dict1 == dict2)

a)

True

b)

False

9.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

10.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
11.

What would this out put? print(users[0][2])

a)

23

b)

ben

c)

sam

d)

smith

12.

a={1:"A",2:"B"}

a.clear()

print(a)

a)

None

b)

{ None:None, None:None, None:None}

c)

{1:None, 2:None, 3:None}

d)

{ }

13.

Select the all correct way to remove the key marks from a dictionary

student = { "name": "Emma", "class": 9, "marks": 75 }

a)

student.pop("marks")

 

b)

del student["marks"]

 

c)

student.remove("marks")

14.

What will be the result of

d={'a':1,'b':2,"c":3}

print(d[0])

a)

a

b)

b

c)

c

d)

Error

15.

What will be printed by the following statement?

d={"cat":12,"dog":6,"elephant":23,"bear":20}

print("dog" in d)

a)

True

b)

False

c)

Error

d)

None

16.

Which one below is a correct dictionary ?

a)

>>> age = {‘Mary’: 10, ‘Sanjay’: 8}

b)

>>> age = (‘Mary’: 10, ‘Sanjay’: 8)

c)

>>> age = {‘Mary’, 10: ‘Sanjay’, 8}

d)

>>> age = {‘Mary’, '10': ‘Sanjay’, '8'}

17.

What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}

for i,j in a.items():

print(i,j,end=" ")

a)

1 A 2 B 3 C

b)

1 2 3

c)

A B C

d)

1:”A” 2:”B” 3:”C”

18.

What will be the output of the following Python code snippet?

>>> a={1:"A",2:"B",3:"C"}

>>> del a

a)

method del doesn’t exist for the dictionary

b)

del deletes the values in the dictionary

c)

del deletes the entire dictionary

d)

del deletes the keys in the dictionary

19.

dl={1:10, 2:20, 3:30, 4:40}

d2={5:50, 6:60, 7:70}

dl.update (d2)

print (dl)

a)

[(1, 10), (2, 20), (3, 30), (4, 40), (5, 50)]

b)

{1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60, 7: 70}

c)

{1:10, 2: 20, 4: 40, 5: 50, 6: 60, 7: 70}

d)

[1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60, 7: 70]

20.

Select the all correct way to remove the key ‘Salary‘ from a dictionary

emp = { "name": "John", "Designation": "Manager", "Salary": 90000,}

a)

emp.pop(“Salary”)

b)

del emp[“Salary”]

c)

emp.popitem()

d)

emp.remove(“key2”)

21.

To view all the keys in the dictionary which function is used?

a)

dict.function()

b)

dict.keys()

c)

dict.values()

d)

I don't Know

22.

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

a)

d = dict([

('foo', 100),

('bar', 200),

('baz', 300)

])

b)

d = {}

d['foo'] = 100

d['bar'] = 200

d['baz'] = 300

c)

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

d)

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

e)

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