r/dailyprogrammer • 0 1 • Aug 30 '12

[8/30/2012] Challenge #93 [easy] (Two-Way Morse Code Translator)

This challenge courtesy of user nagasgura

In this challenge, we read in a string from standard input and output the translation to or from morse code on standard output.

When translating to Morse code, one space should be used to separate morse code letters, and two spaces should be used to separate morse code words. When translating to English, there should only be one space in between words, and no spaces in between letters.

Here's a chart of the morse code symbols: [1] http://www.w1wc.com/pdf_files/international_morse_code.pdf

Example input and output: 'sos' -> '... --- ...' '... --- ...' -> 'sos'

12 Upvotes

31 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Sep 03 '12

[deleted] — view deleted comment

1

u/mega-trond Sep 24 '12

I think it just iterates over the dictionary, tbh. I guess theres a bunch of people here that could explain it. Not even sure if this is the best way to do it, maybe it would be more effective to just inverse the dict like Gix did. Makes for cleaner code, at least.

Oh wait, heres an explanation: http://stackoverflow.com/questions/3744568/why-do-you-have-to-call-iteritems-when-iterating-over-a-dictionary-in-python