user1747134 user1747134 - 3 months ago 55
Python Question

Evaluate iterator in python

I have a lazy iterator/generator

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.


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

collections.deque(iterator, maxlen=0)