Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Composition of Functions solution in Creative category for Morse Encoder by flpo
from functools import reduce
from re import Scanner
from operator import itemgetter
compose = lambda *funcs: lambda x: reduce(lambda y, f: f(y), reversed(funcs), x)
M = (('0', '-----'), ('1', '.----'), ('2', '..---'), ('3', '...--'), ('4', '....-'),
('5', '.....'), ('6', '-....'), ('7', '--...'), ('8', '---..'), ('9', '----.'),
('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', '--..'), (' ', ' '))
morse_encoder = compose(' '.join, itemgetter(0), Scanner(M).scan, str.upper)
March 24, 2018