Morse Message Decoder
Morse code represents text using short and long signals, so decoding it is a nice way to practice splitting strings and using a dictionary. Write decode_morse, which takes a dictionary morse and a string message, then converts the codes back into regular characters. Letters are separated by one space, words are separated by three spaces, and any extra spaces around the message should be ignored.
Примеры
Ввод
{".-": "A", "-...": "B", "-.-.": "C"}, ".-"Вывод
"A"Ввод
{".....": "5", "....-": "4", "...--": "3"}, "..... ....-"Вывод
"54"Ввод
{".-": "A", "-...": "B", "-.-.": "C"}, " .- -... -.-. "Вывод
"AB C"Нужно реализовать
def decode_morse(morse: dict, message: str) -> str:
Теги
stringsdict
Logi sisse, et näha esituste ajalugu
Logi sisseLogi sisse, et kasutada AI mentorit
Logi sisseVisible tests
1
Input
{".-":"A","-.-.":"C","-...":"B"}, ".-"Expected
"A"2
Input
{"...--":"3","....-":"4",".....":"5"}, "..... ....-"Expected
"54"3
Input
{".-":"A","-.-.":"C","-...":"B"}, " .- -... -.-. "Expected
"AB C"4
Input
{"-":"T",".":"E"}, ". -"Expected
"ET"5
Input
{"-":"T",".":"E"}, ". -"Expected
"E T"6
Input
{"...--":"3","....-":"4",".....":"5"}, ""Expected
""Focus radio
Paused · SomaFM · Fluid