Consume an iterable

Peter Otten __peter__ at
Sat Jan 23 15:19:56 CET 2010

Muhammad Alkarouri wrote:

> On 23 Jan, 13:46, Peter Otten <__pete... at> 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.


More information about the Python-list mailing list