Collection in Python MCQs Exercise I


Ques 1 Collection


Which collection type in Python is an ordered dictionary of key-value pairs?
  a) List
  b) Tuple
  c) Set
  d) OrderedDict


d is the correct option





Ques 2 Collection


What is the output of the following code snippet?


from collections import deque
my_deque = deque([1, 2, 3])
my_deque.appendleft(0)
print(my_deque)

  a) [0, 1, 2, 3]
  b) [1, 2, 3, 0]
  c) [0, 1, 2]
  d) [1, 2, 3]


a is the correct option





Ques 3 Collection


Which collection type in Python is an unordered collection of unique elements with constant-time average for basic operations?
  a) List
  b) Tuple
  c) Set
  d) OrderedDict


c is the correct option





Ques 4 Collection


What is the output of the following Python Code?

from collections import defaultdict
my_dict = defaultdict(int)
my_dict['a'] += 1
my_dict['b'] += 2
print(my_dict['c'])

  a) 0
  b) 1
  c) 2
  d) KeyError


a is the correct option





Ques 5 Collection


What is the output of the following Python Code?

from collections import ChainMap
dict1 = {'a': 1, 'b': 2}
dict2 = {'b': 3, 'c': 4}
combined_dict = ChainMap(dict1, dict2)
print(combined_dict['b'])

  a) 1
  b) 2
  c) 3
  d) KeyError


c is the correct option