Question 1 of 25
Hints left: 3
Q1
If a is a dictionary with some key-value pairs, what does a.popitem() do?
Q2
What will be the output of the following Python code snippet? d = {"john":40, "peter":45} "john" in d
Q3
What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} b=a.copy() b[2]="D" print(a)
Q4
What will be the output of the following Python code snippet? a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count)
Q5
What will be the output of the following Python code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)
Q6
What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1]
Q7
If b is a dictionary, what does any(b) do?
Q8
What will be the output of the following Python code? >>> import collections >>> b=dict() >>> b=collections.defaultdict(lambda: 7) >>> b[4]
Q9
What will be the output of the following Python code? >>> a={i: i*i for i in range(6)} >>> a
-
A
-
B
-
C
-
D
Q10
What will be the output of the following Python code? >>> a={"a":1,"b":2,"c":3} >>> b=dict(zip(a.values(),a.keys())) >>> b
Q11
What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(5,4))
Q12
What will be the output of the following Python code snippet? >>> a={1:"A",2:"B",3:"C"} >>> del a
Q13
Which of the following is not a declaration of the dictionary?
Q14
What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} b={4:"D",5:"E"} a.update(b) print(a)
Q15
Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use?
Q16
What will be the output of the following Python code? a={1:5,2:3,3:4} a.pop(3) print(a)
Q17
What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} a.clear() print(a)
Q18
What will be the output of the following Python code snippet? d = {"john":40, "peter":45} d["john"]
Q19
Which of the following isn't true about dictionary keys?
Q20
What will be the output of the following Python code snippet? a={} a['a']=1 a['b']=[2,3,4] print(a)
Q21
What will be the output of the following Python code snippet? a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count)
Q22
What will be the output of the following Python code snippet? total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))
Q23
Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?
Q24
What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.setdefault(3))
Q25
What will be the output of the following Python code snippet? >>>import collections >>> a=collections.Counter([1,1,2,3,3,4,4,4]) >>> a
-
A
-
B
-
C
-
D