Commits

Mike Ruckman  committed 9ddb088

Added ability to go from morse back to string and handling spaces.

  • Participants
  • Parent commits 2df11d8

Comments (0)

Files changed (1)

     """
     return [lookup[c.upper()] for c in s]
 
+def morse_to_string(morse_list):
+    """Return a string from a list of morse code characters.
+
+    >>> print morse_to_string(['-..', '..-', '.-.', '..', '-.',
+    ...                        '....-', '..---'])
+    DURIN42
+    """
+    return ''.join([lookdown[key] for key in morse_list])
+
 
 lookup = {'!': '-.-.--',
           "'": '.----.',
           'Y': '-.--',
           'Z': '--..',
           '_': '..--.-',
+          ' ': ' ',
           }
+
+lookdown = dict([(value, key) for key, value in lookup.iteritems()])