To start this lab, download this zip file.
Lab 22 - Dictionary Lookup
Activities
decipher.py
Write a function decipher(codex, secret_message)
that uses the dictionary codex
to decode secret message
.
For example:
codex = {"s": "i",
"y": "a",
"e": "m",
"q": "g",
"p": "r",
"n": "o",
"t": "t"}
decipher(codex, "S ye Qpnnt!")
Would return:
I am Groot!
auto_correct.py
Write a function auto_correct(correct_words,text)
where correct_words
is a dictionary that maps commonly misplelled words to their correct spelling. Use correct words
to autocorrect any applicable mispellings in text
.
correct_words= {"Teh": "The",
"mispelled": "misspelled",
"corects": "corrects"}
auto_correct(correct_words, "Teh function corects mispelled words!")
Would return:
The function corrects misspelled words!
shopping_cart_total.py
Write a function shopping_cart_total(cart, prices)
where cart
is a dictionary that maps shopping items to the quantity
bought (eg. “forks”: 4) and prices
is a dictionary that maps store items to how much they cost (eg. “milk”: 2.99).
Use cart
and prices
to compute the total cost of all items in the cart.
For example:
cart = {"apple": 3, "soup": 5, "ramen": 3, "milk": 1}
prices = {"apple": 1, "soup": 3, "ramen": 1, "milk": 2}
shopping_cart_total(cart, prices)
Would return:
23
postal_routing.py
Write a function postal_routing(item_to_address, zip_code_to_delivery_bin)
where item_to_address
maps an item id to a street address and zip_code_to_delivery_bin
maps a zip code to its postal delivery bin.
Use item_to_address
and zip_code_to_delivery_bin
to create a new dictionary that maps an item id to its delivery bin.
For example:
item_to_address = {"Violin": "221B Baker St.,London,5208",
"Cheese": "62 West Wallaby Street,Wigan,Lancashire,227",
"Umbrella": "17 Cherry Tree Lane,London,5208",
"Spatula": "124 Conch Street,Bikini Bottom,Pacific Ocean,12345"}
zip_code_to_delivery_bin = {5208: 16,
227: 76,
12345: 1}
postal_routing(item_to_address, zip_code_to_delivery_bin)
Would return:
{"Violin": 16,
"Cheese": 76,
"Umbrella": 16,
"Spatula": 1}
assign_convocation_room.py
Write a function assign_convocation_room(name_to_major, major_to_college, college_to_room)
where name_to_major
maps a students name to their major, major_to_college
maps a major to its department/college, and college_to_room
maps a college/department to the room number where their meeting will be held.
Use these three dictionaries to create a new dictionary that maps each student to their assigned room number.
For example:
name_to_major = {"Jimmer Fredette": "American Studies", "Brandon Sanderson": "English", "Lindsey Stirling": "Recreation Management"}
major_to_college = {"American Studies": "Humanities", "English": "English", "Recreation Management": "Recreation Management"}
college_to_room = {"Humanities": 377, "English": 322, "Recreation Management": 258}
assign_convocation_room(name_to_major, major_to_college, college_to_room)
Would return:
{"Jimmer Fredette": 377, "Brandon Sanderson": 322, "Lindsey Stirling": 258}
Grading
Activity | Points |
---|---|
decipher.py | 6 points |
auto_correct.py | 6 points |
shopping_cart_total.py | 6 points |
postal_routing.py | 6 points |
assign_convocation_room.py | 6 points |