Skip to content

Instantly share code, notes, and snippets.

@samson-wang
Last active October 24, 2017 10:28
Show Gist options
  • Save samson-wang/4e0ee1f3788e225315ddd2014768b068 to your computer and use it in GitHub Desktop.
Save samson-wang/4e0ee1f3788e225315ddd2014768b068 to your computer and use it in GitHub Desktop.
阿里妹1024
M_C = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..']
A_C = ['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']
M_C += ['.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.', '-----']
A_C += ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
BASE_DICT = dict(zip(M_C, A_C))
TASH = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ali_str = '..-./----./-..../...--/..-/..-./----./.----/-..-/-..-/..-./...../----./-.--/----./..-./-..../..---/.----/.----/..-./-..../--.../-..../...../..-./....-/...-/---../-....'
de_morse = ''.join([BASE_DICT.get(_) for _ in ali_str.split('/')])
print de_morse
de_t = ''
for k, i in enumerate(de_morse):
if i in TASH:
# print TASH[25-TASH.index(i)]
de_t += TASH[25-TASH.index(i)]
else:
de_t += i
print de_t.replace('U', '\\u').decode('unicode-escape')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment