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

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]

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

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

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