We’re starting off with all the English words and Pirate words in two separate lists where the positions of the lists correspond. It is associated lists like this work but when a mapping solution is required, dictionaries are often a more natural implementation. (a) Your first job is to redesign the approach and turn these two lists into one dictionary. The words, both English and Pirate language, are distinct, so either one can be the key. Here are the original lists (feel free to add your own words; we got them by googling “Pirate Talk”) ENGLISH = ['hello', 'friend', 'hey', 'awful', 'wow','reward', 'song', 'money', 'board', 'cocktail', 'bathroom', 'friends', 'cheat', 'flag','boy', 'girl', 'my', 'take', 'sink', 'telescope', 'clean', 'you'] PIRATE = ['ahoy', 'matey', 'avast', 'bilge-sucking', 'blimey', 'booty', 'chanty', 'dubloon', 'plank', 'grogg', 'head', 'hearties', 'hornswaggle', 'jack', 'lad', 'lass', 'me', 'plunder', 'scuttle', 'spyglass', 'swob', 'ye'] (b) Now that you have your dictionary set up, prompt the user for a sentence, and then translate from English into Pirate. Allow the user to enter upper or lowercase letters but assume no punctuation. Use a while loop to keep prompting for a sentence to translate until the user enters ‘arr’
Simple Dictionaries: Pirate-Talk Translator
We’ll use a Python dictionary as an actual dictionary. As we discussed in our lecture this week, a dictionary is really good for 1-1 mapping of concepts-to-values, so that's what we'll do here.
We’re starting off with all the English words and Pirate words in two separate lists where the positions of the lists correspond. It is associated lists like this work but when a mapping solution is required, dictionaries are often a more natural implementation.
(a) Your first job is to redesign the approach and turn these two lists into one dictionary. The words, both English and Pirate language, are distinct, so either one can be the key.
Here are the original lists (feel free to add your own words; we got them by googling “Pirate Talk”)
ENGLISH = ['hello', 'friend', 'hey', 'awful', 'wow','reward', 'song', 'money',
'board', 'cocktail', 'bathroom', 'friends', 'cheat', 'flag','boy',
'girl', 'my', 'take', 'sink', 'telescope', 'clean', 'you']
PIRATE = ['ahoy', 'matey', 'avast', 'bilge-sucking', 'blimey', 'booty', 'chanty',
'dubloon', 'plank', 'grogg', 'head', 'hearties', 'hornswaggle',
'jack', 'lad', 'lass', 'me', 'plunder', 'scuttle', 'spyglass', 'swob',
'ye']
(b) Now that you have your dictionary set up, prompt the user for a sentence, and then translate from English into Pirate. Allow the user to enter upper or lowercase letters but assume no punctuation. Use a while loop to keep prompting for a sentence to translate until the user enters ‘arr’.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images