Page 385 - Computer Science Class 11 With Functions
P. 385
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 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)
Dictionaries 383

