-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path[6 kyu]Decode the Morse code.py
More file actions
21 lines (18 loc) · 1.01 KB
/
[6 kyu]Decode the Morse code.py
File metadata and controls
21 lines (18 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MORSE_CODE = {'.-...': '&', '--..--': ',', '....-': '4',
'.....': '5', '...---...': 'SOS', '-...': 'B', '-..-': 'X',
'.-.': 'R', '.--': 'W', '..---': '2', '.-': 'A', '..': 'I',
'..-.': 'F', '.': 'E', '.-..': 'L', '...': 'S', '..-': 'U',
'..--..': '?', '.----': '1', '-.-': 'K', '-..': 'D', '-....': '6',
'-...-': '=', '---': 'O', '.--.': 'P', '.-.-.-': '.', '--': 'M', '-.': 'N',
'....': 'H', '.----.': "'", '...-': 'V', '--...': '7', '-.-.-.': ';',
'-....-': '-', '..--.-': '_', '-.--.-': ')', '-.-.--': '!', '--.': 'G',
'--.-': 'Q', '--..': 'Z', '-..-.': '/', '.-.-.': '+', '-.-.': 'C',
'---...': ':', '-.--': 'Y', '-': 'T', '.--.-.': '@', '...-..-': '$',
'.---': 'J', '-----': '0', '----.': '9', '.-..-.': '"', '-.--.': '(',
'---..': '8', '...--': '3'}
def decodeMorse(morseCode):
MORSE_CODE['@'] = ' '
morseCode = morseCode.strip().replace(' ',' @ ')
return ''.join([MORSE_CODE[code] for code in morseCode.split()])
print(decodeMorse('.... . -.-- .--- ..- -.. . '))
# H E Y J U D E