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>2 mistakes here</p>

<ol>
<li>you convert to uppercase but test against lower!</li>
<li>you should iterate on a copy of <code>ROOMNAMEinventory</code>, modifying list while iterating on it is not recommended: it changes lists to that <code>['string', 'lamp']
and ['coin']</code>: not that you want</li>
</ol>

<p>Fixed code:</p>

<pre><code>ROOMNAMEinventory = ['lamp', 'coin']
inventory = ['string']
do = raw_input("What would you like to do?").upper()
if(do == 'DROP ALL'):  # upper vs upper: could work :)
  for items in ROOMNAMEinventory[::]:  # iterate on a copy of the list
    inventory.append(items)
    ROOMNAMEinventory.remove(items)
print inventory
print ROOMNAMEinventory
</code></pre>

<p>result (when inputting <code>drop all</code>)</p>

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

python list