Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
having fun solution in Creative category for Morse Encoder by roman.bratishchev
# build MORSE on the principle of dichotomic search table:
# https://en.wikipedia.org/wiki/Morse_code#Alternative_display_of_common_characters_in_International_Morse_code
build_morse=lambda table,depth,x='',i=-1: {table[i:i+1]:x}|(
build_morse(table,depth-1,x+'.',i*2+2)|build_morse(table,depth-1,x+'-',i*2+3) if depth else {}
)
MORSE=build_morse('etianmsurwdkgohvf_l_pjbxcyzq__54_3___2_______16_______7___8_90',5)
# ignore heading, trailing and consecutive spaces
morse_encoder=lambda t,p='': ' '.join(
MORSE.get((p:=c).lower(),' ') for c in t if c!=' ' or p not in ' '
)[:-2*(p==' ') or None]
March 22, 2025