Removing items from dictionaries


I still do not understand the difference between deleting an entry and removing one. If I do this for example

backpack = [‘xylophone’, ‘dagger’, ‘tent’, ‘bread loaf’]

print backpack

del backpack[‘tent’]
print backpack

I get this message:
[‘xylophone’, ‘tent’, ‘bread loaf’] Traceback (most recent call last): File “python”, line 4, in module. TypeError: list indices must be integers, not str.


deleting deletes an item at a specific index, del is expecting an index, not a list item/value.


what about in exercise 12 where we used del dict_name[key_name] such as in del zoo_animals[‘Sloth’]


that is different, then the argument to del is a dictionary. del deletes based on key for dictionary and based on index for list.