Question 1
Find the output of the following program:
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:
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:
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:
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:
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:
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:
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:
dict ={}
print (all(dict))
{ }
False
True
An exception is thrown
Question 9
Find the output of the following program:
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
There are 24 questions to complete.