[Chicago] Can this be done with a yield statement and generator object?

Tim Ottinger tottinge at gmail.com
Tue Nov 10 12:14:47 EST 2015


You mean, like itertools.cycle?


On Tue, Nov 10, 2015 at 11:09 AM, Lewit, Douglas <d-lewit at neiu.edu> wrote:

> That's very logical, Will, thanks!   :-)
>
> On Tue, Nov 10, 2015 at 9:02 AM, William E. S. Clemens <
> wesclemens at gmail.com> wrote:
>
>> I didn't test, but something like this should do the same.
>>
>> def circular_list(array):
>>       while True:
>>             counter = -1
>>             if counter == len(array) - 1:
>>                   counter = -1
>>             counter+=1
>>             yield array[counter]
>>
>>
>> On Tue, Nov 10, 2015 at 2:10 AM, Lewit, Douglas <d-lewit at neiu.edu> wrote:
>>
>>> Hey guys,
>>>
>>> I'm attaching a simple class that I created in Python.... Python 3 to be
>>> specific, but I think it should work in Python 2 as well, maybe.  Anyhow,
>>> is there a way to implement the same concept using a *yield statement*
>>> in a function to create a generator object?  Just wondering.  Let me know,
>>> thanks!
>>>
>>> Best,
>>>
>>> Douglas Lewit
>>>
>>> P.S.  Obviously if you use a generator object to do this then the
>>> generator object would never produce the StopIteration error.  But I'm kind
>>> of confused about how to create and define a generator object that would
>>> produce this cyclical behavior in an array or list.
>>>
>>>
>>>
>>> _______________________________________________
>>> Chicago mailing list
>>> Chicago at python.org
>>> https://mail.python.org/mailman/listinfo/chicago
>>>
>>>
>>
>>
>> --
>> William Clemens
>> Phone: 847.485.9455
>> E-mail: wesclemens at gmail.com
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>


-- 
Tim Ottinger, Anzeneer, Industrial Logic
-------------------------------------
http://www.industriallogic.com/
http://agileotter.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20151110/9f332581/attachment.html>


More information about the Chicago mailing list