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

William E. S. Clemens wesclemens at gmail.com
Tue Nov 10 10:02:42 EST 2015

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
            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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20151110/10fe9023/attachment.html>

More information about the Chicago mailing list