-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_morse.py
25 lines (22 loc) · 1.06 KB
/
decode_morse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
print('From Code Wars.')
print()
def decodeMorse(morse_code):
# This function decodes a morse code to readable message.
dict_morse_code = {
'.-': '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', '.----': '1',
'..---': '2', '...--': '3', '....-': '4',
'.....': '5', '-....': '6', '--...': '7',
'---..': '8', '----.': '9', '-----': '0',
'--..--': ', ', '.-.-.-': '.', '..--..': '?',
'-..-.': '/', '-....-': '-', '-.--.': '(',
'-.--.-': ')', '...---...': 'SOS', '-.-.--': '!', '/': ' '
}
return ' '.join(''.join([' ' if item == '' else dict_morse_code[item]
for item in morse_code.split(' ')]).split())
print(decodeMorse('.... . -.-- .--- ..- -.. .')) # Outputs - HEY JUDE