Why not just loop over a string?
a_string="abcd" for letter in a_string: print letter
returns
a b c d
So, in pseudo-code, I would do the following:
user_string = raw_input() list_of_output = [] for letter in user_string: list_of_output.append(morse_code_ify(letter)) output_string = "".join(list_of_output)
Note: morse_code_ify is a pseudo-code.
You definitely want to create a list of characters that you want to output, and not just concatenate them at the end of a line. As stated above, this is O (n ^ 2): bad. Just add them to the list and then use the "".join(the_list) .
As a note: why do you remove spaces? Why not just return morse_code_ify(" ") a "\n" ?
source share