Created
June 10, 2018 10:52
-
-
Save navidanindya/ff0f22eec0d0c35a30b40b7987a43423 to your computer and use it in GitHub Desktop.
Decode Morse code using Python. [ Link: https://repl.it/@nealtheguitaris/AcceptableWellinformedDifference ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
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', | |
'-----': '0', '.----': '1', '..---': '2', '...--': '3', '....-': '4', | |
'.....': '5', '-....': '6', '--...': '7', '---..': '8', '----.': '9', | |
'.-.-.-': '.', '--..--': ',', '..--..': '?', '.----.': "'", '-.-.--': '!', | |
'-..-.': '/', '-.--.': '(', '-.--.-': ')', '.-...': '&', '---...': ':', | |
'-.-.-.': ';', '-...-': '=', '.-.-.': '+', '-....-': '-', '..--.-': '_', | |
'.-..-.': '"', '...-..-': '$', '.--.-.': '@', '...---...': 'SOS' | |
} | |
def decodeMorse(morse_code): | |
return re.sub(' +',' ',''.join([MORSE_CODE[i] if i else ' ' for i in morse_code.split(' ')])).strip() | |
print(decodeMorse('.-- .. - .... --- .-. .-- .. - .... --- ..- - -.-- --- ..-')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment