How to pass values to a generator in a for loop?
<p>I know that you can use <code>.send(value)</code> to send values to an generator.  I also know that you can iterate over a generator in a for loop.  Is it possible to pass values to a generator while iterating over it in a for loop?</p>

<p>What I'm trying to do is</p>

<pre><code>def example():
    previous = yield
    for i range(0,10):
        previous = yield previous*i

t = example()
for value in example"...pass in a value?...":
    "...do something with the result..."
</code></pre>

<p>Ok, so I figured it out.  The trick is to create an additional generator that wraps <code>t.send(value)</code> in a for loop <code>(t.send(value) for value in [...])</code>.</p>

<pre><code>def example():
    previous = yield
    for i in range(0,10):
        previous = yield previous * i

t = examplr()
t.send(None)
for i in (t.send(i) for i in ["list of objects to pass in"]):
    print i
</code></pre>

python generator