On Thu, Feb 9, 2012 at 7:33 PM, Peter Otten <__pete...@web.de> wrote:
> Chris Angelico wrote:
>
>> def cycle(seq,n):
>>         seq=iter(seq)
>>         lst=[next(seq) for i in range(n)]
>>         try:
>>                 while True: yield next(seq)
>>         except StopIteration:
>>                 for i in lst: yield i
>
> I think that should be spelt
>
> def cycle2(seq, n):
>    seq = iter(seq)
>    head = [next(seq) for i in range(n)]
>    for item in seq:
>        yield item
>    for item in head:
>        yield item

Thanks, yeah, don't know what I was thinking :) Too much C work lately!

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to