Created
January 4, 2015 04:19
-
-
Save crackwitz/684344749c3524d6a493 to your computer and use it in GitHub Desktop.
morsecode
This file contains hidden or 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
alphabet = { | |
' ': ' ', | |
'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': '----.' | |
} | |
timings = { | |
'.': [1], | |
'-': [1] * 3, | |
' ': [0], | |
} | |
def morsecode(message): | |
# inter-letter space | |
message = ' '.join(message) | |
message = ''.join(alphabet[letter] for letter in message) | |
message = ' '.join(message) | |
message = sum([timings[c] for c in message], []) | |
return message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment