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.