Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
list solution in Clear category for Morse Encoder by kurosawa4434
MORSE = ['54 3 2 16 7 8 90',
'hvf l pjbxcyzq ',
'surwdkgo',
'ianm',
'et']
TONE = '.-'
def morse_encoder(text):
result = []
for c in text.lower():
if c == ' ':
result.append(' ')
continue
for i in range(len(MORSE)):
idx = MORSE[i].find(c)
if idx > -1:
rs = ''.join(TONE[(idx//(2**(j-i))) % 2] for j in range(i, len(MORSE)))
result.append(rs[::-1])
return ' '.join(result)
if __name__ == '__main__':
assert morse_encoder("some text") == "... --- -- . - . -..- -"
assert morse_encoder("2018") == "..--- ----- .---- ---.."
assert morse_encoder("It was a good day") == ".. - .-- .- ... .- --. --- --- -.. -.. .- -.--"
print("Coding complete? Click 'Check' to earn cool rewards!")
March 24, 2018
Comments: