[Python-ideas] "continue with" for dynamic iterable injection
Tim Delaney
timothy.c.delaney at gmail.com
Thu Sep 25 02:03:07 CEST 2014
On 25 September 2014 08:09, Cathal Garvey <cathalgarvey at cathalgarvey.me>
wrote:
>
> The idea is that `continue with` would allow injection of any datatype
> or variable, which becomes the next iterated item. So, saying `continue
> with 5` means that the next *x* in a loop structured as `for x in..`
> would be 5.
>
You can effectively do this just with generators.
def process(iterable):
for e in iterable:
yield e
yield -e
for e in process([1, 2, 3]):
print(e)
If you need to get more complex, investigate the send() method of
generators.
Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140925/e15bd392/attachment.html>
More information about the Python-ideas
mailing list