Skip to content

Instantly share code, notes, and snippets.

@macloo
Created February 25, 2025 12:58
Show Gist options
  • Save macloo/a0d4608be569d717463d85dbcda648f6 to your computer and use it in GitHub Desktop.
Save macloo/a0d4608be569d717463d85dbcda648f6 to your computer and use it in GitHub Desktop.
Fix line breaks in a string by changing them to spaces
# 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