Initializing a list and appending in one line
<p>How can I initialize a list, if it is not already initialized and append to it in one line. For example,</p>

<pre><code>function example(a=None):
   a = a or []
   a.append(1)
   return another_function(a)
</code></pre>

<p>How can I combine those two statements in the function into one?</p>

<p>I am looking for something like this, but that does not work:</p>

<pre><code>function example(a):
   a = (a or []).append(1)
   return another_function(a)
</code></pre>

<p>EDIT: I don't reference <code>a</code> elsewhere, it is just being passed from function to function. Practically just value is important, so it is OK if it is another object with the right value. I also added a default value of None. </p>

<pre><code>def example(a):
    return a + [1] if a else [1]

&gt;&gt;&gt; example([1,2,3])
[1, 2, 3, 1]
&gt;&gt;&gt; example([])
[1]
</code></pre>

python