Python: How to initialize a list with generator function
<p>Let's say i have 2 following functions:</p>

<pre><code>def get_items():
    items = []
    for i in xrange(2, 10):
        items.append(i)
    return items

def gen_items():
    for i in xrange(2, 10):
        yield i
</code></pre>

<p>I know i can use both of them in a for loop like this</p>

<pre><code>for item in gen_items():
    do something
</code></pre>

<p>But now i need to initialize a variable as list, like this</p>

<pre><code>mylist = get_items()
</code></pre>

<p>but with the generator function. Is there a way to do it without a for loop appending the items from generator?</p>

<p>The list builtin will accept any iterator: </p>

<pre><code>l = list(gen_items())
</code></pre>

python generator