1.11M Members

delete an item in a list which is in a dictionary

 
0
 
inventory = {'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'],
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}

how do i delete the item 'dagger' only from the 'backpack'

 
0
 

This might help you:

try:
    inventory.get('backpack').remove('dagger')
except ValueError:
    pass
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article