Page 437 - Computer Science V2.0 Class 11
P. 437
D. Answer the following questions:
1. What will be the output produced on execution of the following code snippet:
d1 = {1:2, 3:4}
d2 = {3:4, 1:2}
print(d1 == d2)
Ans. True
2. What will be the output produced on execution of the following code snippet:
d1 = {1:2, 3:4}
d2 = {1:2, 3:4}
print(d1 is d2)
Ans. False
3. What will be the output produced on execution of the following code snippet:
myDict = {}
val = 0
d = myDict.fromkeys([1,2,3,4],'val')
print(d)
Ans. {1: 'val', 2: 'val', 3: 'val', 4: 'val'}
4. What will be the output produced on execution of the following code snippet:
myDict = {}
val = 0
myDict.fromkeys([1,2,3,4],'val')
print(myDict)
Ans. {}
5. What will be the output produced on execution of the following code snippet:
myDict = {}
val = 0
d = myDict.fromkeys([1,2,3,4],val)
print(d)
Ans. {1: 0, 2: 0, 3:0, 4: 0}
6. What will be the output produced on execution of the following sequence of steps, executed in IDLE:
>>> myDict={ }
>>> myDict[1] = {1:'One',2:'Two'}
>>> myDict[2] = [1,2,3,4]
>>> print(myDict)
Ans. {1: {1: 'One', 2: 'Two'}, 2: [1, 2, 3, 4]}
7. What will be the output produced on execution of the following code snippet:
>>> myDict = dict()
>>> for k in range(5):
... myDict[k+1] = (k+1)*(k+1)
>>> print(myDict)
Ans. {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
8. What will be the output produced on execution of the following code snippet:
d1 = {1:11, 2:22}
print(sum(d1), sum(d1.keys()), sum(d1.values()))
Ans. 3 3 33
Dictionaries 423

