Question: Here is the code in a Python dictionary, where the keys are letters and the values are the corresponding Morse codes. morsecode = { '

Here is the code in a Python dictionary, where the keys are letters and the values are the corresponding Morse codes.
morsecode ={'a': '.-',
'b': '-...',
'c':'-.-.',
'd':'-..',
'e':'.',
'f':'..-.',
'g':'--.',
'h':'....',
'i':'..',
'j':'.---',
'k':'-.-',
'l':'.-..',
'm':'--',
'n':'-.',
'o':'---',
'p':'.--.',
'q':'--.-',
'r':'.-.',
's':'...',
't':'-',
'u':'..-',
'v':'...-',
'w':'.--',
'x':'-..-',
'y':'-.--',
'z':'--..'}
For example, the Morse code for 'a boy' is '.--...----.--'
We will adopt the convention that in the Morse code output there is always a space between two letters and there are three spaces between words. Write a function called morse(mystring, code) that takes as input a string and a dictionary (e.g., the Morse code dictionary above), and returns the Morse code version of that string. You can cut-and-paste the dictionary above into your function. For example:
>>> morse('a boy', morsecode)
'.--...----.--'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!