Drop Item If More Than 1 Item Present
<p>I'm working on a piece of code, and it is for a little AI creature to randomly come into a room, and look to see if there is anything there. If there is anything that the player has touched before, then it takes the item. The next room it goes to it drops that item and may pick up a new one. So far, I have:</p>

<pre><code>import random
rooms = ['kitchen', 'livingroom', 'basement']
itemsstatus = {'Umbrella': 1, 'Coin': 1}
itemsstatus['Umbrella'] = raw_input()
print "itemstatus['Umbrella']", itemsstatus['Umbrella']
roominventory = ['Umbrella', 'Coin']
goblininventory = ['baseball']
notpickedanythingelse = 'true'

gotoroom = random.choice(rooms)
if(gotoroom == 'kitchen') or (gotoroom == 'livingroom') or (gotoroom == 'basement'):
    ininventory = len(goblininventory)
    if(ininventory &gt;= 1):
        roominventory.append(goblininventory[0])
        goblininventory.remove([0])
    else:
      print ""  

    for items in roominventory:
        if(itemsstatus[items] == 1) and (notpickedanythingelse == 'true'):
            goblininventory.append(items)
            roominventory.remove(items)
            notpickedanythingelse = 'false'
        else:
            print ""
    notpickedanythingelse = 'true'

    print roominventory
    print goblininventory
</code></pre>

<p>The itemstatus[''] = rawinput() will be done automatically by the game and won't be a raw imput, it is just here so I can test it. As well, each room will have it's own inventory and loop, but this is just for the simplicity of it. The goblin will pick up an item, and keep it, but it won't drop the one it already has (it can only carry 1 thing at a time). How can I get it so that it will drop the item it is holding once entering a new room?</p>

<p><code>goblininventory.remove([0])</code> is incorrect.  You should use <code>goblininventory.pop()</code> to remove the first element from the list.</p>

<p>See here for more info on <code>remove</code> and <code>pop</code>: <a href="https://docs.python.org/2/tutorial/datastructures.html#more-on-lists" rel="nofollow">https://docs.python.org/2/tutorial/datastructures.html#more-on-lists</a></p>

python