Write a Python function called consume(iterator, n) that advances a given iterator by n steps in-place…
Write a Python function called consume(iterator, n) that advances a given iterator by n steps in-place…: a task in repo2rlenv-r2e (Harbor dataset). Behavior requirements: - If n is a non-negative integer, advance the iterator exactly n steps (or until exhausted if fewer than n elements remain). -…
The task
Behavior requirements: - If `n` is a non-negative integer, advance the iterator exactly `n` steps (or until exhausted if fewer than `n` elements remain). - If `n` is `None`, fully exhaust the iterator, consuming all remaining elements. - If `n` is 0, the iterator should remain unchanged. - The function must work with…
Part of FineEnvs/repo2rlenv-r2e.