How to update a composite list as contents of member lists are changed?
<p>Let's say I have:</p>

<pre><code>friendlies = []
enemies = []
everyone = [friendlies + enemies]
</code></pre>

<p>And I say:</p>

<pre><code>friendlies.append("something")
</code></pre>

<p>so that friendlies now contains:</p>

<pre><code>["something"]
</code></pre>

<p>What is the pythonic way to make it so that <code>everyone</code> updates as well? So that if I update <code>friendlies</code> in the way stated above, <code>everyone</code> would contain:</p>

<pre><code>["something"] 
</code></pre>

<p>?</p>

<p>If you sum now you lose reference. Create a list of lists to maintain references</p>

<p>Hacky way of doing that:</p>

<pre><code>friendlies = []
enemies = []

everyone = [friendlies,enemies]  # not sum, sublists
enemies.append("something")
print(sum(everyone,[]))   # sum sublists to a new list
</code></pre>

python list python-3.x data-structures