Generator
R. David Murray
rdmurray at bitdance.com
Mon Mar 23 10:13:50 EDT 2009
John Posner <jjposner at snet.net> wrote:
>
> [snip]
> > > If you want next(g) to yield 3, you'd have to do something like:
> > >
> > > g = (x for x in s[:])
> > >
> > > where s[:] makes a copy of s that is then iterated over.
>
>
> BTW, this simpler statement works, too:
>
> g = iter(s[:])
Yes, but one presumes that in the real code that prompted the OP's
question he wasn't just returning 'x'.
--
R. David Murray http://www.bitdance.com
More information about the Python-list
mailing list