Dictionary In Python MCQs
Practice Dictionary In Python MCQs for competitive exams.
Dictionary In Python MCQs
Practice questions from this topic.
What will be the output of the following Python code snippet? numbers = {} letters = {} comb = {} numbers[1] = 56 numbers[3] = 7 letters[4] = 'B' comb['Numbers'] = numbers comb['Letters'] = letters print(comb)
Correct Answer: D
What will be the output of the following Python code snippet? >>> import collections >>> a=collections.Counter([2,2,3,3,3,4]) >>> b=collections.Counter([2,2,3,4,4]) >>> a|b
Correct Answer: A
What will be the output of the following Python code snippet? d = {"john":40, "peter":45}
Correct Answer: B
What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(1,4))
Correct Answer: B
What will be the output of the following Python code? >>> b={} >>> all(b)
Correct Answer: C
What will be the output of the following Python code? >>> a={i: 'A' + str(i) for i in range(5)} >>> a
Correct Answer: B
Which of the following isn't true about dictionary keys?
Correct Answer: C
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
Correct Answer: D
What will be the output of the following Python code? >>> import collections >>> b=dict() >>> b=collections.defaultdict(lambda: 7) >>> b[4]
Correct Answer: D
What will be the output of the following Python code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)
Correct Answer: A
What will be the output of the following Python code snippet? a={} a['a']=1 a['b']=[2,3,4] print(a)
Correct Answer: D
Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?
Correct Answer: C
