The problem is that you are not doing anything with the result of replace. In Python strings are immutable so anything that manipulates a string returns a new string instead of modifying the original string.

line[8] = line[8].replace(letter, "")
Answer from Matti Virkkunen on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_string_replace.asp
Python String replace() Method
Remove List Duplicates Reverse ... Study Plan Python Interview Q&A Python Training ... The replace() method replaces a specified phrase with another specified phrase. Note: All occurrences of the specified phrase will be replaced, ...
Discussions

Making str.replace() accept lists - Ideas - Discussions on Python.org
Syntax of the method: str.replace(old, new, count=-1) What if replace could accept two lists instead of two strings. Often I find in code: text.replace(a, b).replace(c, d) The concatenation of replace calls can cause a unnecessary performance hit if the string is large or the call is the calls ... More on discuss.python.org
🌐 discuss.python.org
3
May 9, 2020
Python: How can I replace one specific character on a string while leaving the rest of the string as it was?
str.replace replaces all instances of the search string with the replacement string, which isn't what you want the correct solution would be to turn the string into a list, update the value at the wanted index and then "".join(char_list) to rebuild the string More on reddit.com
🌐 r/learnprogramming
12
6
October 18, 2023
How to replace a string that is all the same character at a specific index?
Slice and concatenate. string1 = string1[:-1] + 'b' More on reddit.com
🌐 r/learnpython
10
10
May 4, 2024
Is there an easier way to replace multiple different things at once
On a high level, the method you’ve demonstrated is both idiomatic and the fastest (or one at least one of them). However, a bit of reorganization will make it both a little more efficient (by not leaving the file handle open as long), and will ensure it looks cleaner and more readable. More on discuss.python.org
🌐 discuss.python.org
4
1
March 14, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-replace-all-occurrences-of-a-substring-in-a-string
Python - Replace all Occurrences of a Substring in a String - GeeksforGeeks
August 13, 2026 - Explanation: re.sub(pattern, replacement, string) finds all occurrences of pattern and replaces them with replacement. This method splits the string at each occurrence of the target and joins it back with the replacement.
🌐
StrataScratch
stratascratch.com › blog › how-to-replace-a-character-in-a-python-string
How to Replace a Character in a Python String - StrataScratch
October 18, 2024 - The basic method for replacing a string in Python is intuitively named str.replace(). It allows you to specify one character or a whole substring you want to replace and a character (or a substring) you want to replace it with.
🌐
Python.org
discuss.python.org › ideas
Making str.replace() accept lists - Ideas - Discussions on Python.org
May 9, 2020 - Syntax of the method: str.replace(old, new, count=-1) What if replace could accept two lists instead of two strings. Often I find in code: text.replace(a, b).replace(c, d) The concatenation of replace calls can cause a unnecessary performance hit if the string is large or the call is the calls ...
🌐
Mimo
mimo.org › glossary › python › string-replace-method
Master Python's String Replace Method for Text Manipulation
Learn basics, data types, control flow, and more ... The replace() method returns a copy of the string after replacing the substrings without changing the original string. ... count: An optional parameter that specifies the number of occurrences to replace. The default value (-1) replaces all ...
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python
Replace Strings in Python: replace(), translate(), and Regex
May 4, 2025 - To replace the content in a text file, read the file into a string, process it, and save the result back to the file. Read, write, and create files in Python (with and open()) The replace() method replaces all occurrences of a substring with another.
🌐
YouTube
youtube.com › real python
Replacing a String In a String in Python - YouTube
This a preview of a video course about replacing strings in Python. If you’re looking for ways to remove or replace all or part of a string in Python, then t...
Published: August 24, 2023
Views: 1K
🌐
Real Python
realpython.com › replace-string-python
How to Replace a String in Python – Real Python
October 22, 2025 - In this tutorial, you'll learn how to remove or replace a string or substring. You'll go from the basic string method .replace() all the way up to a multi-layer regex pattern using the sub() function from Python's re module.
🌐
Quora
quora.com › How-do-you-replace-all-occurrences-of-a-character-in-a-string-in-Python
How to replace all occurrences of a character in a string in Python - Quora
Answer (1 of 3): Let’s assume you need to replace all ‘X’ characters in a 10 character string with ‘Y’. You can do this by replacing all characters with ‘Y’. For example: 1. You start with the ten character string: “BoX of BoXes”. 2. You iterate through the string replacing ...
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
The pattern may be a string or a Pattern. The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. If omitted or zero, all occurrences will be replaced.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-replace
Python String replace() Method - GeeksforGeeks
July 7, 2026 - count (optional): Specifies the maximum number of replacements to perform. If omitted, all occurrences are replaced. Return Value: A new string with the specified replacements applied. The original string is not modified because strings in Python are immutable.
🌐
Python.org
discuss.python.org › python help
Is there an easier way to replace multiple different things at once - Python Help - Discussions on Python.org
March 14, 2022 - im trying to use the .replace() mutiple times at once and i was wondering if there was a cleaner way to do it Code example: with open("user_data.txt", "w") as f: f.write(str(user_data).replace("{","{\n").replace("}…
🌐
All About AI-ML
indhumathychelliah.com › 2020 › 12 › 20 › different-ways-to-replace-occurences-of-a-substring-in-python-strings
Different Ways to Replace Occurences of a Substring in Python Strings – All About AI-ML
January 2, 2022 - 1. Replace all occurrences of substring ‘Using str.replace()’ Syntax: str.replace(old,new,count) Example 1: Replace substring “two” by “one” s1="one apple,two orange,two banana"…
🌐
Server Academy
serveracademy.com › blog › python-replace-function
Python Replace() Function Blog | Server Academy
November 14, 2024 - The method in Python is a powerful tool for working with strings, allowing you to replace parts of a string with new values. Whether you’re changing characters…
🌐
Quora
quora.com › In-Python-how-do-I-use-the-replace-function-on-strings-to-replace-multiple-characters-e-g-a-space-or-any-special-character-with-the-empty-string-E-g-Tes-ting-replace-only-replaces-the-space-not-the
In Python, how do I use the .replace() function on strings to replace multiple characters, e.g. a space or any special character, with th...
Answer (1 of 4): Why do you ask how to use a function (method) to do something after you’ve already demonstrated to yourself that the function/method doesn’t do that? Perhaps it’s better to describe what you want to accomplish and ask which functions or methods might already exist to ...
🌐
freeCodeCamp
freecodecamp.org › news › python-string-replace-function-in-python-for-substring-substitution
Python String.Replace() – Function in Python for Substring Substitution
January 24, 2022 - You can even replace a whole string of text with a new line of text that you specify. The .replace() method returns a copy of a string. This means that the old substring remains the same, but a new copy gets created – with all ...