Difference between chain(*iter) vs chain.from_iterable(iter)
<p>I have been really fascinated by all the interesting iterators in itertools and one confusion I have had is the difference between these two functions and why chain.from_iterator exists.</p>

<pre><code>from itertools import chain

def foo(n):
    for i in range(n):
        yield [i, i**2]

chain(*foo(5))

chain.from_iterable(foo(5))
</code></pre>

<p>What is the difference between the two functions?</p>

<p><code>*</code> unpacks the iterator, meaning it iterates the iterator in order to pass its values to the function. <code>chain.from_iterable</code> iterates the iterator one by one lazily.</p>

python