Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I would edit that message after you have settled a bit.
did you benchmark and compare this solution to yours?
whats the result?
my guess is you solution is even worse because of regular string reallocations in
output += MORSE_CODE[item]
andtry/except
is not free eitherdouble loop solution is simple and easy to understand - split words, split letters, convert, join letters to words, join words to sentence
your solution:
split by space and try to decode each "letter"
if next "letter" is '' then it must be word separator - append space, and on next cycle too, and on next
and wrap it in
try/except
because processing last letter will causelist index out of range.
exception inmorse[index + 1]
flow control via exceptions is a big no-no
and it took me almost 10 mins to comprehend your algorithm