For Loop Append to list from another
<p>I'm working on a "pick up all" and "drop all" for a game I'm designing. The player has an inventory (inventory) and each room has it's own to keep track of what is in it. When it is a specific item, I can easily append or remove the item from the respective lists, but when it is for them all, I am not sure how to proceed. (NOTE: I won't know how many items are in the inventories as it will change as players take and drop items)</p>

<pre><code>ROOMNAMEinventory = ['lamp', 'coin']
inventory = ['string']
do = raw_input("What would you like to do?").upper()
if(do == 'drop all'):
  for items in ROOMNAMEinventory:
    inventory.append(items)
    ROOMNAMEinventory.remove(items)
print inventory
print ROOMNAMEinventory
</code></pre>

<p>Currently, this prints out:</p>

<pre><code>['string', 'lamp']
['coin']
None
</code></pre>

<p>Why does it print the None?</p>

<p><code>List</code> in Python supports adding one to another:</p>

<pre><code>roomname_inventory = ['lamp', 'coin']
inventory = ['string']
do = raw_input("What would you like to do?").upper()
if (do == 'DROP ALL'):
    inventory += roomname_inventory
    roomname_inventory = []
print inventory
print roomname_inventory
</code></pre>

<p>But if you just want to get rid of modifying the list while iterating over it, you could also do:</p>

<pre><code>if (do == 'DROP ALL'):
    while roomname_inventory:
        inventory.append(roomname_inventory.pop(0))
</code></pre>

python list