-
Notifications
You must be signed in to change notification settings - Fork 2
/
Week-4
34 lines (27 loc) · 1.15 KB
/
Week-4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
1. Consider the following Python function.
def mystery(l):
if l == []:
return(l)
else:
return(mystery(l[1:])+l[:1])
What does mystery([22,14,19,65,82,55]) return?
[55, 82, 65, 19, 14, 22]
2. What is the value of pairs after the following assignment?
pairs = [ (x,y) for x in range(4,1,-1) for y in range(5,1,-1) if (x+y)%3 == 0 ]
[(4, 5), (4, 2), (3, 3), (2, 4)]
3. Consider the following dictionary.
wickets = {"Tests":{"Kumble":[3,5,2,3],"Srinath":[4,4,1,0],"Prasad":[2,1,7,4]},"ODI":{"Kumble":[2,0],"Srinath":[1,2]}}
Which of the following statements does not generate an error?
wickets["ODI"]["Prasad"][0:] = [4,4]
wickets["ODI"]["Prasad"].extend([4,4])
wickets["ODI"]["Prasad"] = [4,4]
wickets["ODI"]["Prasad"] = wickets["ODI"]["Prasad"] + [4,4]
wickets["ODI"]["Prasad"] = [4,4]
4. Assume that hundreds has been initialized as an empty dictionary:
hundreds = {}
Which of the following generates an error?
hundreds["Tendulkar, international"] = 100
hundreds["Tendulkar"] = {"international":100}
hundreds[("Tendulkar","international")] = 100
hundreds[["Tendulkar","international"]] = 100
hundreds[["Tendulkar","international"]] = 100