Problem of the Day
A new programming or logic puzzle every Mon-Fri

Morse Code Translator

Today's problem is a fun one for the next time you get ship wrecked on a desert island. Create a function that when given a string of text will print out the message in morse code. This chart should be of use.

morse code chart

Permalink: http://problemotd.com/problem/morse-code-translator/

Comments:

  • Anonymous - 9 years, 9 months ago

    import string
    
    morse_map = dict(zip(['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....',
                          '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.',
                          '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-',
                          '-.--', '--..'], string.ascii_uppercase))
    en_map = {b:a for a,b in morse_map.items()}
    
    def morse_decode(st):
        return "".join(morse_map[c] for c in st.split())
    
    def morse_encode(st):
        return " ".join(en_map[c] for c in st.upper())
    

    reply permalink

  • Max Burstein - 9 years, 9 months ago

    Nice!

    reply permalink

  • Anonymous - 9 years ago

    nice

    reply permalink

Content curated by @MaxBurstein