Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20064
| References | <mailman.5525.1328663401.27778.python-list@python.org> <4f3343b2$0$1615$c3e8da3$76491128@news.astraweb.com> <CAPTjJmo2BkybBo8Kd_Hk5tapq_YrSHHCk0zJmYTO408YShGWFA@mail.gmail.com> <jh00ca$7eu$1@dough.gmane.org> |
|---|---|
| Date | 2012-02-09 21:34 +1100 |
| Subject | Re: Cycle around a sequence |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5578.1328783688.27778.python-list@python.org> (permalink) |
On Thu, Feb 9, 2012 at 7:33 PM, Peter Otten <__peter__@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Cycle around a sequence Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-02-08 01:10 +0000
Re: Cycle around a sequence Christoph Hansen <ch@radamanthys.de> - 2012-02-08 03:01 +0100
Re: Cycle around a sequence Neil Cerutti <neilc@norwich.edu> - 2012-02-08 14:25 +0000
Re: Cycle around a sequence Terry Reedy <tjreedy@udel.edu> - 2012-02-08 15:15 -0500
Re: Cycle around a sequence Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-02-08 22:47 +0000
Re: Cycle around a sequence Serhiy Storchaka <storchaka@gmail.com> - 2012-02-09 12:10 +0200
Re: Cycle around a sequence Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-09 03:55 +0000
Re: Cycle around a sequence Chris Angelico <rosuav@gmail.com> - 2012-02-09 15:16 +1100
Re: Cycle around a sequence Peter Otten <__peter__@web.de> - 2012-02-09 09:33 +0100
Re: Cycle around a sequence Chris Angelico <rosuav@gmail.com> - 2012-02-09 21:34 +1100
csiph-web