Why not just iterate through the string?

a_string="abcd"
for letter in a_string:
    print letter

returns

a
b
c
d

So, in pseudo-ish code, I would do this:

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: the morse_code_ify function is pseudo-code.

You definitely want to make a list of the characters you want to output rather than just concatenating on them on the end of some string. As stated above, it's O(n^2): bad. Just append them onto a list, and then use "".join(the_list).

As a side note: why are you removing the spaces? Why not just have morse_code_ify(" ") return a "\n"?

Answer from mellort on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_strings.asp
Python Strings
To check if a certain phrase or character is present in a string, we can use the keyword in. ... txt = "The best things in life are free!" if "free" in txt: print("Yes, 'free' is present.") Try it Yourself » · Learn more about If statements in our Python If...Else chapter.
🌐
Tu-delft-dcc
tu-delft-dcc.github.io › Intro-to-Python-for-GIS › Instructor_notes › Day_1 › lesson_notes › B2_Vars_Types.html
Use an index to get a single character from a string. — Python essentials for GIS learners
thing[number:some-negative-number] returns a slice from number to some-negative-number values from the end of thing · If a part of the slice is out of range, the operation does not fail. atom_name[0:15] gives the same result as atom_name[0:]. {: .solution} {: .challenge} Guide to programing with Python for the Digital Humanities Functions may only work for certain (combinations of) arguments.
🌐
GeeksforGeeks
geeksforgeeks.org › python-program-to-read-character-by-character-from-a-file
Python program to read character by character from a file - GeeksforGeeks
September 6, 2024 - Open a file in read mode that contains a string then use an Infinite while loop to read each character from the file the loop will break if no character is left in the file to read then Display each word of length 5 from each line in the text file.
🌐
Python
mail.python.org › pipermail › tutor › 2006-August › 048830.html
[Tutor] How do I make Python read a string character by character?
September 1, 2013 - On 8/24/06, Nathan Pinno <falcon3166 at hotmail.com> wrote: > How do I make Python read a string character by character? >>> str = 'string' >>> for i in range(0, len(str)): ... print str[i] ... s t r i n g just take care about the indentation.
🌐
O'Reilly
oreilly.com › library › view › python-cookbook › 0596001673 › ch03s02.html
Processing a String One Character at a Time - Python Cookbook [Book]
July 19, 2002 - Processing a String One Character at a TimeCredit: Luther BlissettProblemYou want to process a string one character at a time. SolutionYou can use list with the string as its... - Selection from Python Cookbook [Book]
Authors   Alex MartelliDavid Ascher
Published   2002
Pages   608
🌐
Educative
educative.io › answers › how-to-get-the-characters-in-a-string-in-python
How to get the character(s) in a string in Python
You can use a negative index starting from the end of a string to get the character of a string, as shown below. ... In the example below, you can use the same syntax to extract a few characters instead of just one.
Find elsewhere
🌐
Google
developers.google.com › google for education › python › python strings
Python Strings | Python Education | Google for Developers
Characters in a string can be accessed using the standard [ ] syntax, and like Java and C++, Python uses zero-based indexing, so if s is 'hello' s[1] is 'e'. If the index is out of bounds for the string, Python raises an error.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-extract-only-characters-from-given-string
Python - Extract only characters from given string - GeeksforGeeks
July 11, 2025 - The re.sub function replaces all non-alphabetic characters with an empty string (''), effectively extracting only the letters from the input string.
🌐
Real Python
realpython.com › python-strings
Strings and Character Data in Python – Real Python
December 22, 2024 - In this tutorial, you'll learn how to use Python's rich set of operators and functions for working with strings. You'll cover the basics of creating strings using literals and the str() function, applying string methods, using operators and built-in functions with strings, and more!
🌐
GeeksforGeeks
geeksforgeeks.org › python › iterate-over-characters-of-a-string-in-python
Iterate over characters of a string in Python - GeeksforGeeks
July 11, 2025 - If we need both the character and its index then enumerate() is a great choice. It returns both values in each iteration. ... The print function uses a formatted string, where the f before the string allows us to include variables directly within ...
🌐
GitConnected
levelup.gitconnected.com › introduction-to-strings-in-python-18caf6e02152
Introduction to Strings in Python | by Rany ElHousieny | Level Up Coding
October 31, 2025 - You can access individual characters in a string by using indexing. In Python, indexing starts from 0, so the first character of a string is at index 0, the second character is at index 1, and so on.
🌐
CodeBasics
code-basics.com › programming › python course › extracting characters from a string
Extracting characters from a string | Python | CodeBasics
[Python] — Extracting characters from a string — Sometimes, you have to get a single character from a string. For example, if a site knows users' first and last names, and at some point you want it to output this inf...
🌐
Bobby Hadz
bobbyhadz.com › blog › python-read-file-character-by-character
How to Read a file character by character in Python | bobbyhadz
April 10, 2024 - On each iteration of the while loop, we add the current character to a list. The list.append() method adds an item to the end of the list. Alternatively, you can use a for loop. ... Open the file in reading mode.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
September 29, 2025 - The slicing method [::-1] is generally preferred because it’s concise, readable, and efficient. In this tutorial, we’ve explored the fundamental concepts of indexing and slicing strings in Python 3, which are crucial for manipulating text data. We learned that strings, like lists and tuples, are sequence-based data types, allowing us to access their individual characters and portions using these powerful techniques. ... Indexing: How to retrieve a single character from a string using its numerical position (index), both from the beginning (positive indices starting at 0) and from the end (negative indices starting at -1).
🌐
Quora
quora.com › How-do-you-access-a-range-of-characters-from-a-string-in-Python
How to access a range of characters from a string in Python - Quora
Answer (1 of 3): Python – Extract range characters from String Given a String, extract characters only which lie between given letters. > Input : test_str = ‘geekforgeeks is best’, strt, end = “g”, “s” Output : gkorgksiss Explanation : All characters after g and before s are retained.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Extract a Substring from a String in Python (Position, Regex) | note.nkmk.me
April 29, 2025 - If you want to extract a substring from the contents of a text file, first read the file as a string. Read, write, and create files in Python (with and open()) You can get a character at a specific position by specifying its index in []. Indexes start at 0 (zero-based indexing).
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string
Python String - GeeksforGeeks
Strings are indexed sequences. Positive indices start at 0 from the left, negative indices start at -1 from the right as represented in below image: ... Example 1: Access specific characters through positive indexing. ... Note: Accessing an index out of range will cause an IndexError. Only integers are allowed as indices and using a float or other types will result in a TypeError. Example 2: Read characters from the end using negative indices.
Published   1 week ago