Ad
  • Default User Avatar
  • Default User Avatar

    I would edit that message after you have settled a bit.

  • Default User Avatar

    "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 cause list index out of range. exception in morse[index + 1]"

    Not true. Code doesn't iterate trough each letter in every word

    Exception neglects KeyError when searching in dictionary

    "flow control via exceptions is a big no-no"

    Not true for python

    Your code (apocryphal , probably)

    "for letter in word.split(' ')) for word in morseCode.strip().split(' '))"

    Nested loop (efficiency killer)

    My code could be improved. What abut "yours"?

  • Custom User Avatar

    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] and try/except is not free either

    double 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 cause list index out of range. exception in morse[index + 1]

    flow control via exceptions is a big no-no

    and it took me almost 10 mins to comprehend your algorithm

  • Default User Avatar

    You can also start enumerating from any int you want
    in this case it would be
    enumerate(str(n),p)
    I recommend always to check the documentation whenever you see something new

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution