Python Development Course
Chapter
>
Level

Using Dictionaries
More complex operations

Objective

Go through all the crates in the shed and remove junk from each crate.

The crates in the shed are a mess, each crate holds a dictionary which has undesired items inside. These items include: “Pipes”, “Screws” and “Bolts”. When working with dictionaries there’s an easy way to remove items from them by accessing their index.

# crate = {"Planks": 4, "Bricks" : 2, "Pipes": 3} del crate["Pipes"] # Now dictionary holds: crate = {"Planks": 4, "Bricks" : 2}

In the above code there is a dictionary named crate that holds planks, bricks and pipes. The del notation is used to remove the index for “Pipes” for the dictionary along with it’s value.

There are five dictionary constants in this level: crate1, crate2, crate3, crate4 and crate5. Walk to the X marks in front of each crate and use the speak() function with the name of each dictionary so you can read out what items are inside of the crate. Use the del notation to remove any “Pipes”, “Screws” and “Bolts” found in each crate.

Code book