On 23 Jan, 13:46, Peter Otten <__pete...@web.de> wrote: > Peter Otten wrote: > > Duncan Booth wrote: > > >> Peter Otten <__pete...@web.de> wrote: > > >>> With next(islice(...), None) I seem to have found a variant that beats > >>> both competitors. > > >> It has different behaviour for n==0 but I'm sure that's easily fixed. > > > "Different behaviour" being a euphemism for broken ;) > > > def consume_islice(n, items): > > if n == 0: > > return > > next(islice(items, n-1, None), None) > > Even better: > > def consume_islice(n, items): > next(islice(items, n, n), None) > > Peter
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:) If you are happy with this one, and can add the comment on the issue (http://bugs.python.org/issue7764) yourself, please do so. What I can say is, I am definitely very happy that I asked the question. You live and learn:) Cheers, Muhammad -- http://mail.python.org/mailman/listinfo/python-list