Retruning multiple objects and using them as arguments
<p>I have a function which goes something like this:</p>

<pre><code>def do_something(lis):
    do something
    return lis[0], lis[1]
</code></pre>

<p>and another function which needs to take those two return objects as arguments:</p>

<pre><code>def other_function(arg1, arg2):
    pass
</code></pre>

<p>I have tried:</p>

<pre><code>other_function(do_something(lis))
</code></pre>

<p>but incurred this error:</p>

<pre><code>TypeError: other_function() missing 1 required positional argument: 'arg2'
</code></pre>

<p>You can do it like this:</p>

<pre><code>other_function(*do_something(list))
</code></pre>

<p>The <code>*</code> char will expand the <code>tuple</code> returned by <code>do_something</code>.</p>

<p>Your <code>do_something</code> function is actually returning a <code>tuple</code> which contains several values but <strong>is</strong> only one value itself.</p>

<p>See <a href="https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">the doc</a> for more details.</p>

python function functional-programming return arguments