Exercise: Standard Libraries

Questions for: Standard Libraries

How can you use the collections.Counter class in Python to count the occurrences of elements in a list?
A:
counter.count_elements()
B:
collections.count()
C:
Counter.count()
D:
collections.Counter()
Answer: D
from collections import Counter

# Example usage of collections.Counter
my_list = [1, 2, 3, 1, 2, 1, 4, 5, 4, 3, 2]
element_counts = Counter(my_list)
print(element_counts)
What does the multiprocessing module in Python provide?
A:
Asynchronous I/O operations
B:
Functions for working with multiprocessing
C:
Generating random numbers
D:
Sorting elements in a list
Answer: B
The multiprocessing module in Python provides functions and classes for working with multiprocessing, allowing the execution of parallel processes.
Which module in Python provides functions for working with regular expressions in a more advanced and powerful manner than the re module?
A:
regexlib
B:
advancedre
C:
relib
D:
regex
Answer: D
The regex module in Python provides functions for working with regular expressions in a more advanced and powerful manner than the re module.
What is the purpose of the collections.namedtuple() function?
A:
Creating named tuples with named fields
B:
Sorting elements in a list
C:
Handling dates and times
D:
Parsing JSON data
Answer: A
The collections.namedtuple() function in Python is used to create named tuples with named fields.
Which module in Python provides support for interacting with the operating system, including functions for file and directory manipulation?
A:
sysutils
B:
os
C:
fileops
D:
operatingsystem
Answer: B
The os module in Python provides support for interacting with the operating system, including functions for file and directory manipulation.
Ad Slot (Above Pagination)
Quiz