Page 221 - Information_Practice_Fliipbook_Class11
P. 221
3. All the keys in a dictionary must be of the same type. __________
4. A key in a dictionary can not be a mutable data type. __________
5. If d is a dictionary, d[0] will yield its first key. __________
6. If subjects = {'Sanskrit': 78, 'English': 185, 'Maths': 88,
'Hindi': 90} is a dictionary, subjects[0] will yield an error because a dict object
is not subscriptable. __________
7. If d is a dictionary, d.keys()[0] will yield its first key. __________
C. Fill in the blanks.
1. The expression print(len({1: 2, 2: 3, 1:2})) yields ____________.
2. Consider a dictionary:
myDict = {1:{2}, 2: {3: 5}}
The expression 3 in myDict yields ____________.
3. While working in IDLE environment, a dictionary rollnoMarks of key value pairs rollNo: marks has just been
created:
>>> rollnoMarks = {1:60,2:25,3:90,4:32,5:12,6:78}
The function call ____________ will yield the marks for the candidate with rollNo 4 and remove the pair 4:32 from
rollnoMarks.
4. Consider the dictionary given in Ques 3. The expression print(sorted(rollnoMarks.values())) yields
____________.
5. Consider a dictionary having the student details as follows:
studentDetails = {'Name':'Varun','Roll No': 5,'Marks':90}
The expression print(studentDetails.get('Roll No')) yields ____________.
6. Consider the same dictionary given in Ques. 5, the expression print(studentDetails.get('Roll Number'))
yields ____________.
D. Answer the following questions:
1. What will be the output produced on the 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 the 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 the 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'}
Python Dictionaries 207

