Re: itertools cycle() docs question

2019-08-22 Thread Terry Reedy
On 8/22/2019 11:35 AM, Dennis Lee Bieber wrote: On Wed, 21 Aug 2019 12:52:44 -0700, Tobiah declaimed the following: I see. What is an example of an iterable that is not reusable? Essentially all iterators, which included all generators, which includes the return from all generator functio

Re: itertools cycle() docs question

2019-08-22 Thread Chris Angelico
On Fri, Aug 23, 2019 at 1:41 AM Dennis Lee Bieber wrote: > > On Wed, 21 Aug 2019 12:52:44 -0700, Tobiah declaimed the > following: > > > > >I see. What is an example of an iterable that is not reusable? > > > >>> x = range(5) > >>> x > range(0, 5) > >>> > >>> x = range(0, 5) >>> list(x) [0, 1,

Re: itertools cycle() docs question

2019-08-21 Thread Terry Reedy
On 8/21/2019 2:27 PM, Tobiah wrote: In the docs for itertools.cycle() there is a bit of equivalent code given:     def cycle(iterable):     # cycle('ABCD') --> A B C D A B C D A B C D ...     saved = []     for element in iterable:     yield element     saved.ap

Re: itertools cycle() docs question

2019-08-21 Thread Chris Angelico
On Thu, Aug 22, 2019 at 6:55 AM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 8/21/19 2:32 PM, Calvin Spealman wrote: > > The point is to demonstrate the effect, not the specific implementation. > > Once you've gone through the iterable once, it's falsey, > which means that the whi

Re: itertools cycle() docs question

2019-08-21 Thread Dan Sommers
On 8/21/19 2:32 PM, Calvin Spealman wrote: The point is to demonstrate the effect, not the specific implementation. Once you've gone through the iterable once, it's falsey, which means that the while loop will end. But if you copy all the elements to a real list, then the while loop is infinit

Re: itertools cycle() docs question

2019-08-21 Thread Ian Kelly
On Wed, Aug 21, 2019 at 12:36 PM Calvin Spealman wrote: > > The point is to demonstrate the effect, not the specific implementation. But still yes, that's pretty much exactly what it does. The main difference between the "roughly equivalent to" code and the actual implementation is that the forme

Re: itertools cycle() docs question

2019-08-21 Thread Chris Angelico
On Thu, Aug 22, 2019 at 5:56 AM Tobiah wrote: > > On 8/21/19 11:38 AM, Rob Gaddi wrote: > > On 8/21/19 11:27 AM, Tobiah wrote: > >> In the docs for itertools.cycle() there is a bit of equivalent code > >> given: > >> > >> def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D > >> ... sa

Re: itertools cycle() docs question

2019-08-21 Thread Tim Chase
On 2019-08-21 11:27, Tobiah wrote: > In the docs for itertools.cycle() there is > a bit of equivalent code given: > > def cycle(iterable): > # cycle('ABCD') --> A B C D A B C D A B C D ... > saved = [] > for element in iterable: > yield element >

Re: itertools cycle() docs question

2019-08-21 Thread Tobiah
On 8/21/19 11:38 AM, Rob Gaddi wrote: On 8/21/19 11:27 AM, Tobiah wrote: In the docs for itertools.cycle() there is a bit of equivalent code given: def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D ... saved = [] for element in iterable: yield element saved.append(element) while

Re: itertools cycle() docs question

2019-08-21 Thread Rob Gaddi
On 8/21/19 11:27 AM, Tobiah wrote: In the docs for itertools.cycle() there is a bit of equivalent code given:     def cycle(iterable):     # cycle('ABCD') --> A B C D A B C D A B C D ...     saved = []     for element in iterable:     yield element     saved.app

Re: itertools cycle() docs question

2019-08-21 Thread Calvin Spealman
The point is to demonstrate the effect, not the specific implementation. On Wed, Aug 21, 2019 at 2:30 PM Tobiah wrote: > In the docs for itertools.cycle() there is > a bit of equivalent code given: > > def cycle(iterable): > # cycle('ABCD') --> A B C D A B C D A B C D ... >

itertools cycle() docs question

2019-08-21 Thread Tobiah
In the docs for itertools.cycle() there is a bit of equivalent code given: def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D ... saved = [] for element in iterable: yield element saved.append(element) while saved: