Collection in Python MCQs Exercise II

Ques 1 Collection


What is the purpose of the Counter class in the collections module?

A It provides an ordered collection of unique elements.
B It counts the frequency of elements in a collection.
C It provides a mutable collection of key-value pairs.
D It represents an immutable collection of elements.

Ques 2 Collection


What is the output of the following Python Code?

from collections import namedtuple
Person = namedtuple('Person', ['name', 'age', 'gender'])
person1 = Person('Alice', 25, 'Female')
print(person1.age)

A 'Alice'
B 25
C 'Female'
D ('Alice', 25, 'Female')

Ques 3 Collection


What is the output of the following Python Code?

from collections import deque
my_deque = deque([1, 2, 3])
my_deque.append(4)
my_deque.popleft()
print(len(my_deque))

A 1
B 2
C 3
D 4

Ques 4 Collection


What is the output of the following Python Code?

from collections import Counter
my_list = [1, 2, 3, 4, 5, 1, 2, 3, 1, 2]
my_counter = Counter(my_list)
print(my_counter.most_common(1))

A [(1, 3)]
B [(1, 1)]
C [(1, 2)]
D [(2, 3)]