Strings in Python are immutable (meaning that their data cannot be modified) so the replace method doesn't modify the string - it returns a new string. You could fix your code as follows:

for i in hello:
    j = i.replace(' ','')
    k.append(j)

However a better way to achieve your aim is to use a list comprehension. For example the following code removes leading and trailing spaces from every string in the list using strip:

hello = [x.strip(' ') for x in hello]
Answer from Mark Byers on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-ways-to-remove-multiple-empty-spaces-from-string-list
Python - Ways to remove multiple empty spaces from string List - GeeksforGeeks
July 12, 2025 - Using str.replace() in a loop allows for replacing specific substrings in each string of a list or text. This method iterates through the strings applying the replacement operation for each occurrence of the target substring. ... s = ["Hello world", " Python is great ", " Extra spaces here "] # Remove multiple spaces using replace in a loop b = [string.replace(' ', ' ') for string in s] # Repeat the replace step until no double spaces exist a = [string.replace(' ', ' ') for string in b] print(a)
Discussions

How to remove extra space from output list tuple?
Hi, I have this input [python]P (0, 2,+1) (2, 0, -1) (0, 4,+1) (4, 0, -1)[/python] and I would like to have it printed out this way [python][(0, 2, 1), (2, 0, -1), (0, 4, 1), (4, 0, -1)][/python]. However, due to the extra space in the input I ran into this error. More on discuss.python.org
๐ŸŒ discuss.python.org
3
0
May 5, 2022
How to Remove Spaces From a String in Python (Complete 2026 Guide)
That single line removes all whitespace characters from a Python string and is the most robust answer for most real-world use cases. ... Understanding the difference is critical for choosing the correct method. The replace() method replaces occurrences of a substring with another substring. To remove literal spaces... More on accuweb.cloud
๐ŸŒ accuweb.cloud
1
December 1, 2023
Remove brackets and appostrophes from the list
Hello Allโ€ฆI got a simple request, until now cant find solution from google. I want to remove rackets and appostrophes from the list. Ex. list = [3,4,5,] result is = 3,4,5 I tried copy many code but the best i got is = โ€˜3,4,5โ€™ Please helpโ€ฆthanks More on discuss.python.org
๐ŸŒ discuss.python.org
7
0
April 5, 2023
list - How to remove space from a title column in SharePoint online - SharePoint Stack Exchange
I am sure this question has been asked many times, but would someone please be able to guide me with my issue with removing a space between title word, e.g. title "Project ABC" and I woul... More on sharepoint.stackexchange.com
๐ŸŒ sharepoint.stackexchange.com
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ methods to remove spaces from text
r/learnpython on Reddit: methods to remove spaces from text
December 20, 2023 -

Hi everyone, I recently took the Fullstack Python Developer course and am now taking my first steps on this path.
Can you tell me what other methods of removing spaces from text you know and in which case, each of them is better to use?
So far I know 4 of them:

  1. replace method -> text_wo_spaces = text.replace(" ","")

  2. join and split methods -> text_wo_spaces = ' '.join(text.split())

  3. list generator + join -> text_wo_spaces = ' '.join([char for char in text if char != ' '])

  4. filter + join methods -> text_wo_spaces = ' '.join(filter(lambda char : != ' ', text))

๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - Remove all spaces using regex: HelloWorldFromDigitalOceanHiThere Remove leading spaces using regex: Hello World From DigitalOcean Hi There Remove trailing spaces using regex: Hello World From DigitalOcean Hi There Remove leading and trailing spaces using regex: Hello World From DigitalOcean Hi There ยท When removing whitespace from strings, especially in performance-critical applications or when processing large volumes of text, the efficiency of the method you choose matters. This section compares the performance of the primary methods discussed and provides guidance on when to use each one. We will use Pythonโ€™s built-in timeit module to benchmark the replace(), join()/split(), translate(), and re.sub() methods.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ remove-spaces
How to remove spaces in Python - Python Morsels
January 25, 2022 - If you're trying to remove all sorts of whitespace characters (space, tab, newline, etc.) you could use the split and join string methods: If we call split on this version string, Python will split on all consecutive whitespace characters: >>> version = "\tpy 310\n" >>> version.split() ['py', '310'] The string join method can join an iterable of strings by a delimiter (see convert a list ...
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How to remove extra space from output list tuple? - Python Help - Discussions on Python.org
May 5, 2022 - Hi, I have this input [python]P (0, 2,+1) (2, 0, -1) (0, 4,+1) (4, 0, -1)[/python] and I would like to have it printed out this way [python][(0, 2, 1), (2, 0, -1), (0, 4, 1), (4, 0, -1)][/python]. However, due to the extra space in the input I ran into this error.
๐ŸŒ
Accuweb
accuweb.cloud โ€บ home โ€บ how to remove spaces from a string in python (complete 2026 guide)
How to Remove Spaces From a String in Python (Complete 2026 Guide)
December 1, 2023 - That single line removes all whitespace characters from a Python string and is the most robust answer for most real-world use cases. ... Understanding the difference is critical for choosing the correct method. The replace() method replaces occurrences of a substring with another substring. To remove literal spaces: s = "W hi te space" newStr = s.replace(" ", "") print(newStr) Output: WhitespaceCopy
Find elsewhere
๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ how-to-remove-spaces-from-a-string-in-python
How to Remove spaces from a string in Python | Guide by Hostman
This article will cover the methods available in Python (version 3.10.12) for removing spaces from strings.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists_remove.asp
Python - Remove List Items
Python Lists Access List Items Change List Items Add List Items Remove List Items Loop Lists List Comprehension Sort Lists Copy Lists Join Lists List Methods List Exercises Code Challenge Python Tuples
๐ŸŒ
PythonHello
pythonhello.com โ€บ problems โ€บ string โ€บ how-to-remove-all-whitespaces-in-a-string
How to remove all whitespaces in a string in Python
# Initialize the string with ... "Thisisastringwithwhitespaces" You can also use the join() method and a generator expression to remove all whitespaces from a string in Python....
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-trim
How to Trim a String in Python: Three Different Methods | DataCamp
February 16, 2025 - text = "12345Python12345" trimmed_text = text.strip('12345') print(trimmed_text) # Output: "Python" By default, these methods remove all types of whitespace, including spaces, tabs (\t), and newlines (\n).
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ how to remove whitespace from string in python?
How To Remove Spaces from a String in Python? - Scaler Topics
February 14, 2024 - Next, apply the strip() function to each element in the list to remove any leading or trailing spaces. This can be efficiently done using the map() function alongside a lambda expression. Finally, reassemble the list into a single string without any spaces by using the join() function.
๐ŸŒ
Syntx Scenarios
syntaxscenarios.com โ€บ home โ€บ python โ€บ how to remove spaces from a string in python?
How To Remove Spaces From a String in Python?
January 4, 2025 - In Python, you can use a for loop to manually remove spaces from a string by going through each character of the string and checking if itโ€™s a space. If the character is not space, copy it to the new string and if it is a space then just skip it.
๐ŸŒ
YouTube
m.youtube.com โ€บ watch
How To Remove Spaces From A String In Python
Share your videos with friends, family, and the world
Published ย  December 10, 2021
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-remove-whitespaces-from-a-string-in-python
How to Remove Whitespaces from a String in Python
May 27, 2023 - Here, re.sub('\s+', ' ', str_with_whitespace).strip() replaces all consecutive whitespaces with a single space and then removes leading and trailing whitespaces. Advice: Read more about regular expressions in Python in "Introduction to Regular Expressions in Python". List comprehensions provide a concise way to create lists based on existing lists.
๐ŸŒ
CloudSigma
blog.cloudsigma.com โ€บ removing-spaces-in-python
Removing Spaces in Python โ€” CloudSigma
May 16, 2023 - If you want to remove just the leading or tailing spaces, then use lstrip() or rstrip() respectively:
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Remove brackets and appostrophes from the list - Python Help - Discussions on Python.org
April 5, 2023 - Hello Allโ€ฆI got a simple request, until now cant find solution from google. I want to remove rackets and appostrophes from the list. Ex. list = [3,4,5,] result is = 3,4,5 I tried copy many code but the best i got is โ€ฆ
๐ŸŒ
Quora
quora.com โ€บ How-do-you-print-a-list-without-spaces-in-Python
How to print a list without spaces in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
Stack Exchange
sharepoint.stackexchange.com โ€บ questions โ€บ 299560 โ€บ how-to-remove-space-from-a-title-column-in-sharepoint-online
list - How to remove space from a title column in SharePoint online - SharePoint Stack Exchange
You can use replace function in expression in Power automate to remove the spaces from text. ... You can also pass variables or columns from SharePoint list in expressions instead of "'Project resolving any issues'" text.