What is the purpose of the itertools.chain() function?
A. To create chain mail armor
B. To merge multiple iterators into one
C. To filter elements from an iterator
D. To sort elements in an iterator
Answer: Option B
Solution (By Examveda Team)
The correct answer is Option B: To merge multiple iterators into one.The purpose of the itertools.chain() function is to merge multiple iterators into one single iterator. When called with multiple iterable arguments, chain() returns an iterator that yields values from each iterable consecutively, effectively chaining them together into a single sequence. This is useful when you need to iterate over multiple sequences as if they were one continuous sequence, without creating a new combined data structure like a list.
What is a generator in Python?
A. A function that generates random numbers
B. A special type of list
C. A way to define classes
D. A function that yields values one at a time
How is a generator different from a regular function?
A. A generator uses the return keyword
B. A generator can yield multiple values
C. A generator uses the break statement
D. A generator uses the continue statement
What is an advantage of using generators for large datasets?
A. They use more memory
B. They are slower than loops
C. They are easier to implement
D. They use less memory
How do you define a generator function in Python?
A. Using the generator keyword
B. Using the def keyword and yield statement
C. Using the gen keyword
D. Using the function keyword

Join The Discussion