Removing items from dictionaries


#1

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’]

backpack.remove(‘dagger’)
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.


#2

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


#3

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


#4

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