Page 220 - Information_Practice_Fliipbook_Class11
P. 220
5. Which of the following will display the number of key-value pairs in the dictionary myDict?
a. myDict.len() b. len(myDict) c. myDict.size() d. size(myDict)
6. What will be the output produced on the execution of the following code snippet?
myDict = [1,2,{1:'One',2:{3:'Three',4:'Four',5:'Five'},6:'Six'},3,4]
print(5 in myDict,3 in myDict)
a. True False b. True True c. False True d. False False
7. Which of the following is not a correct way to output the sum of the values of the dictionary defined as follows:
>>> myDict = {"One":1,"Two":2,"Three":3}
a. print(sum(myDict.values()))
b. sumValues = 0
for key in myDict.keys():
sumValues += myDict[key]
print(sumValues)
c. print(sum(myDict.keys()))
d. sumValues = 0
for key in myDict:
sumValues += myDict[key]
print(sumValues)
8. Which of the following is not a correct way to output the sum of the keys of the dictionary defined as follows:
>>> myDict = {1:"One",2:"Two",3:"Three"}
a. print(sum(myDict.keys()))
b. sumValues = 0
for value in myDict.keys():
sumValues += value
print(sumValues)
c. print(sum(myDict))
d. sumValues = 0
for key in myDict:
sumValues += myDict[key]
print(sumValues)
9. Consider the following dictionary:
>>> myDict = [1,2,{1:'One',2:{3:'Three',4:'Four',5:'Five'},6:'Six'},3,4]
Which of the following outputs 'Four' from myDict?
a. myDict[2][1][1] b. myDict[2][2][4]
c. myDict[1][2][4] d. myDict[1][1][1]
10. What will be the output produced on execution of the following code snippet?
s = ''
d = {'1':'One','2':'Two'}
for k,v in d.items():
s = k + v
print(s)
a. An error would occur b. 1One2Two c. 2Two d. 1One
B. State whether the following statements are True or False:
1. A dictionary is a sequence of objects over which we can iterate in a for statement. __________
2. Dictionaries are immutable. __________
206 Touchpad Informatics Practices-XI

