Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import pickle
- message = ".... . .-.. .-.. --- / -.. .- .. .-.. -.-- / .--. .-. --- --. .-. .- -- -- . .-. / --. --- --- -.. / .-.. ..- -.-. -.- / --- -. / - .... . / -.-. .... .- .-.. .-.. . -. --. . ... / - --- -.. .- -.--"
- target = open('pickled_morse.p','r+')
- "pickled_morse.p is a serialized dictionary of a morse code alphabet, located at http://pastebin.com/mAkTxPRD"
- morse = dict((v,k) for k, v in pickle.load(target).iteritems()) #{".-":"A"}
- target.close()
- def morse_to_string(msg):
- msg = msg.split()
- word = ''
- for item in msg:
- if item == "/":
- word += " "
- continue
- try:
- word += morse[item]
- except:
- print "Error - could not translate:\t%s" % item
- return word
- if __name__ == "__main__":
- print morse_to_string(message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement