Question: Write a function pirate (e) that translates from English to Pirate, using following dictionary; those words that are not in the dictionary should remain unchanged:
Write a function pirate (e) that translates from English to Pirate, using following dictionary; those words that are not in the dictionary should remain unchanged:

You may assume that the input consists only of lowercase characters. When translating, replace only whole words, like sir or phrases, like how far, but not, for example, sir in desire. For this, consider all characters that are not letters to be separators (for example punctuation). In Python, all characters between 'a' and 'z' are letters, so everything less than 'a' or greater than 'z' is a separator. The same word or phrase can appear multiple times in a sentence, but be careful to avoid translating a translation: pardon my officer should become pardon me foul blaggart and pardon me should not be translated further.

d = {"hello": "ahoy", "hi": "yo-ho-ho", "pardon me": "avast", \ "excuse me": "arrr", "my": "me", "friend": "me bucko", "sir": "matey", "stranger": "scurvy dog", "officer": "foul blaggart",\ "where": "whar", "is": "be", "the": "th"", "you": "ye", \ "tell": "be tellin'", "know": "be knowin'", \ "how far": "how many leagues", "old": "barnacle-covered", \ "attractive": "comely", "happy": "grog-filled", \ "nearby": "broadside", "restroom": "head", "restaurant": "galley", "hotel": "fleabag inn", "pub": "Skull & Scuppers", "bank": "buried treasure"} >>> pirate ('excuse me, sir, do you know how far the old restaurant is?') "arrr, matey, do ye be knowin' how many leagues th' barnacle-covered galley be?" >>> pirate ('tell me officer, where is a nearby bank?') "be tellin' me foul blaggart, whar be a broadside buried treasure?"
Step by Step Solution
3.29 Rating (161 Votes )
There are 3 Steps involved in it
To translate English to Pirate using the given dictionary we can utilize Pythons regular expressions to identify and replace words and phrases Heres a ... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
609350e4a335a_23670.pdf
180 KBs PDF File
609350e4a335a_23670.docx
120 KBs Word File
