3

I have a lazy iterator/generator a which is doing some side-effect on each iteration and I don't care about the values that it produces. What is the most idiomatic way to evaluate the side effects? Of course, I can simply do:

for _ in a: pass

But it seems rather ugly.

10

1 Answer 1

3

I found the recipe for the function consume() in itertools recipes section. Esentially, it recommends to do:

collections.deque(iterator, maxlen=0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.