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)
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))
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))