Consume an iterable

Peter Otten __peter__ at web.de
Sat Jan 23 09:19:56 EST 2010


Muhammad Alkarouri wrote:

> On 23 Jan, 13:46, Peter Otten <__pete... at web.de> wrote:

>> def consume_islice(n, items):
>>     next(islice(items, n, n), None)

> I submitted the bug report before considering this alternative, which
> is better. I may add this later in the day, but I have to wait a
> little as it seems you are going to optimize/improve the function
> almost out of existence:)

One problem: the above function doesn't consume the entire iterator like the 
original example does for n=None. Passing sys.maxint instead is not pretty.

Peter




More information about the Python-list mailing list