Re: Cycle around a sequence

2012-02-09 Thread Chris Angelico
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: >>              

Re: Cycle around a sequence

2012-02-09 Thread Serhiy Storchaka
08.02.12 22:15, Terry Reedy написав(ла): To make a repeating rotator is only a slight adjustment: k = n - len(seq) while True: i = k while i < n: yield seq[i] i += 1 for i in range(n, len(seq)): yield seq[i] while True: fo

Re: Cycle around a sequence

2012-02-09 Thread Peter Otten
Mark Lawrence wrote: > I'm looking at a way of cycling around a sequence i.e. starting at some > given location in the middle of a sequence and running to the end before > coming back to the beginning and running to the start place. About the > best I could come up with is the following, any bett

Re: Cycle around a sequence

2012-02-09 Thread Peter Otten
Chris Angelico wrote: > On Thu, Feb 9, 2012 at 2:55 PM, Steven D'Aprano > wrote: >> If your data is humongous but only available lazily, buy more memory :) > > Or if you have a huge iterable and only need a small index into it, > snag those first few entries into a list, then yield everything el

Re: Cycle around a sequence

2012-02-08 Thread Chris Angelico
On Thu, Feb 9, 2012 at 2:55 PM, Steven D'Aprano wrote: > If your data is humongous but only available lazily, buy more memory :) Or if you have a huge iterable and only need a small index into it, snag those first few entries into a list, then yield everything else, then yield the saved ones: de

Re: Cycle around a sequence

2012-02-08 Thread Steven D'Aprano
On Wed, 08 Feb 2012 01:10:28 +, Mark Lawrence wrote: > I'm looking at a way of cycling around a sequence i.e. starting at some > given location in the middle of a sequence and running to the end before > coming back to the beginning and running to the start place. If you have a sequence, and

Re: Cycle around a sequence

2012-02-08 Thread Mark Lawrence
On 08/02/2012 14:25, Neil Cerutti wrote: On 2012-02-08, Mark Lawrence wrote: I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before coming back to the beginning and running to the start place. About the b

Re: Cycle around a sequence

2012-02-08 Thread Terry Reedy
On 2/8/2012 9:25 AM, Neil Cerutti wrote: On 2012-02-08, Mark Lawrence wrote: I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before coming back to the beginning and running to the start place. About the b

Re: Cycle around a sequence

2012-02-08 Thread Neil Cerutti
On 2012-02-08, Mark Lawrence wrote: > I'm looking at a way of cycling around a sequence i.e. starting > at some given location in the middle of a sequence and running > to the end before coming back to the beginning and running to > the start place. About the best I could come up with is the > fo

Re: Cycle around a sequence

2012-02-08 Thread Tim Golden
On 08/02/2012 08:26, Mark Lawrence wrote: On 08/02/2012 01:26, Dennis Lee Bieber wrote: On Wed, 08 Feb 2012 01:10:28 +, Mark Lawrence wrote: I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before com

Re: Cycle around a sequence

2012-02-08 Thread Mark Lawrence
On 08/02/2012 01:26, Dennis Lee Bieber wrote: On Wed, 08 Feb 2012 01:10:28 +, Mark Lawrence wrote: I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before coming back to the beginning and running to t

Re: Cycle around a sequence

2012-02-07 Thread Christoph Hansen
Mark Lawrence schrieb: I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before coming back to the beginning and running to the start place. About the best I could come up with is the following, any better id

Re: Cycle around a sequence

2012-02-07 Thread Terry Reedy
On 2/7/2012 8:10 PM, Mark Lawrence wrote: I'm looking at a way of cycling around a sequence i.e. starting at some given location in the middle of a sequence and running to the end before coming back to the beginning and running to the start place. About the best I could come up with is the follow