Changing your mind


#1

key - animal_name : value - location

zoo_animals = { ‘Unicorn’ : ‘Cotton Candy House’,
‘Sloth’ : ‘Rainforest Exhibit’,
‘Bengal Tiger’ : ‘Jungle House’,
‘Atlantic Puffin’ : ‘Arctic Exhibit’,
‘Rockhopper Penguin’ : ‘Arctic Exhibit’}

A dictionary (or list) declaration may break across multiple lines

Removing the ‘Unicorn’ entry. (Unicorns are incredibly expensive.)

del zoo_animals[‘Unicorn’]

del zoo_animals[‘Sloth’]
del zoo_animals[‘Bengal Tiger’]

zoo_animals[‘Rockhopper Penguin’] = [‘Arctic Exhibit’]

print zoo_animals

image

I had a quick question. With regards to DELETING i tried
del zoo_animals[‘Sloth’, and ‘Bengal Tiger’]
but it did not work is there a way to just place one entry instead of having to place 2 separate ones?


#2

Sure, you can do this:

del zoo_animals['Unicorn'], zoo_animals['Sloth']

Give it a try.


#3

Using a google search
python using del on more then one dictionary key site:stackoverflow.com
will give you a whole range of articles with discussions / opinions


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.