Created
February 25, 2025 12:58
-
-
Save macloo/a0d4608be569d717463d85dbcda648f6 to your computer and use it in GitHub Desktop.
Fix line breaks in a string by changing them to spaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fix line breaks in name by changing them to spaces | |
# must break string into a list of letters to replace characters, because a string is immutable | |
fullname = "Ruth/nBader/nGinsburg" | |
letter_list = list(fullname) | |
for index, item in enumerate(letter_list): | |
if item == "\n": | |
letter_list[index] = " " | |
new_fullname = "".join(letter_list) | |
# new_fullname now is: "Ruth Bader Ginsburg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment