It's Dangerous to Go Alone! Take This: Using del rather than .remove


#1

How would you go about achieving the same output as below but using del rather than .remove???

inventory = {
'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']
}

inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']

inventory['pouch'].sort()

inventory['pocket'] = ['seashell', 'strange berry', 'lint']
inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] += 50


#2

@bijankle,

Have a read
http://stackoverflow.com/questions/627435/how-to-remove-an-element-from-a-list-by-index-in-python
or
http://stackoverflow.com/questions/5447494/best-way-to-remove-an-item-from-a-python-dictionary


#3

Good point by @leonhard_wettengmx_n! Always make it a point to refer to Stackoverflow and official docs.