The Wayback Machine - https://web.archive.org/web/20250403223009/https://www.geeksforgeeks.org/quizzes/python-dictionary-quiz/

Python Dictionary Quiz

Last Updated :
Discuss
Comments

Question 1

Find the output of the following program:

Python
d = dict() 
for x in enumerate(range(2)): 
	d[x[0]] = x[1] 
	d[x[1]+7] = x[0] 
print(d) 
  • {0: 1, 7: 0, 1: 1, 8: 0}

  • {1: 1, 7: 2, 0: 1, 8: 1}

  • {0: 0, 7: 0, 1: 1, 8: 1}

  • KeyError

Question 2

Find the output of the following program:

Python
d = {1 : 1, 2 : '2', '1' : 1, '2' : 3} 
d['1'] = 2
print(d[d[d[str(d[1])]]]) 
  • 2

  • 3

  • \'2\'

  • KeyError

Question 3

Find the output of the following program:

Python
d = {1 : {'A' : {1 : "A"}, 2 : "B"}, 3 :"C", 'B' : "D", "D": 'E'} 
print(d[d[d[1][2]]], end = " ") 
print(d[d[1]["A"][2]]) 
  • C B

  • E Key Error

  • B D

  • D B

Question 4

Find the output of the following program:

Python
d = dict() 
for i in range (3): 
	for j in range(2): 
		d[i] = j 
print(d) 
  • {0: 0, 1: 0, 2: 0}

  • {0: 1, 1: 1, 2: 1}

  • {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}

  • TypeError: Immutable object

Question 5

Question 5:Find the output of the following program:

Python
d = {1 : [1, 2, 3], 2: (4, 6, 8)} 
d[1].append(4) 
print(d[1], end = " ") 
li = [d[2]]
li.append(10) 
d[2] = tuple(L) 
print(d[2]) 
  • [1, 2, 3, 4] ((4, 6, 8), 10)

  • [1, 2, 3, 4] (4, 6, 8, 10)

  • [1, 2, 3, 4] TypeError: tuples are immutable

  • [1, 2, 3, 4] [4, 6, 8, 10]

Question 6

Find the output of the following program:

Python
a = {i: i * i for i in range(6)} 
print (a) 
  • Dictionary comprehension doesn’t exist

  • {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}

  • {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}

  • {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Question 7

Find the output of the following program:

Python
a ={} 
a.fromkeys(['a', 'b', 'c', 'd'], 98) 
print (a) 
  • Syntax error

  • {‘a’:98, ‘b’:98, ‘c’:98, ‘d’:98}

  • {‘a’:None, ‘b’:None, ‘c’:None.’d’:None}

  • { }

Question 8

Find the output of the following program:

Python
dict ={} 
print (all(dict)) 
  • { }

  • False

  • True

  • An exception is thrown

Question 9

Find the output of the following program:

Python
a = {'geeks' : 1, 'gfg' : 2} 
b = {'geeks' : 2, 'gfg' : 1} 
print (a == b) 
  • True

  • False

  • Error

  • None

Question 10

Which of the following is false about dictionary?

  • The values of a dictionary can be accessed using keys

  • The keys of a dictionary can be accessed using values

  • Dictionaries may or may not be ordered

  • None of the above

"This course is very well structured and easy to learn. Anyone with zero experience of data science, python or ML can learn from this. This course makes things so easy that anybody can learn on their own. It's helping me a lot. Thanks for creating such a great course."-  Ayushi Jain | Placed at Microsoft

Now's your chance to unlock high-earning job opportunities as a Data Scientist! Join our Complete Machine Learning & Data Science Program and get a 360-degree learning experience mentored by industry experts.

Get hands on practice with 40+ Industry Projects, regular doubt solving sessions, and much more. Register for the Program today!

There are 24 questions to complete.

Take a part in the ongoing discussion