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
Python Strings Slicing Strings Modify Strings Concatenate Strings Format Strings Escape Characters String Methods String Exercises Code Challenge Python Booleans
🌐
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 - This method builds a new string by checking each slice for the target substring. It is least efficient but works without built-in functions. ... s = "python java python html python" target = "python" replacement = "c++" res = "" i = 0 while ...
🌐
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.
🌐
Mimo
mimo.org › glossary › python › string-replace-method
Master Python's String Replace Method for Text Manipulation
replace() is a string method that replaces a string’s occurrences of a substring with another substring. The replace() method takes the old substring, the new substring, and an optional count parameter. When present, count specifies the number of occurrences to replace.
🌐
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 are made too many times.
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python
Replace Strings in Python: replace(), translate(), and Regex
May 4, 2025 - In Python, you can replace strings using the replace() and translate() methods, or with regular expression functions like re.sub() and re.subn(). Additionally, you can replace substrings at specific p ...
🌐
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 ...
🌐
pytz
pythonhosted.org › replaceall › README.html
replaceall — replaceall 0.1 documentation
replaceall is a Python 2.7/3 module to replace or remove one or more Chars from a given string.
🌐
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 - After importing the re module, we create the ‘python1234string’ string. Then we use the re.sub() method to replace all digits with ‘X’. Here, \d is a shorthand for the class [0-9], and r denotes a raw string, which ensures special characters are treated literally.
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
However, Unicode strings and 8-bit strings cannot be mixed: that is, you cannot match a Unicode string with a bytes pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string. Regular expressions use the backslash character ('\') to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Python’s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\\\\' as the pattern string, because the regular expression must be \\, and each backslash must be expressed as \\ inside a regular Python string literal.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › replaceAll
String.prototype.replaceAll() - JavaScript | MDN
While it is also possible to use replace() with a global regex dynamically constructed with RegExp() to replace all instances of a string, this can have unintended consequences if the string contains special characters that have meaning in regular expressions (which might happen if the replacement string comes from user input). While you can mitigate this case using RegExp.escape() to make the regular expression string into a literal pattern, it is simpler to pass the string to replaceAll() directly, without converting it to a regex.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-replace
Python String replace() Method - GeeksforGeeks
July 7, 2026 - Return Value: A new string with the specified replacements applied. The original string is not modified because strings in Python are immutable.
🌐
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 ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python regex replace all
Python regex replace all - Spark By {Examples}
May 31, 2024 - In Python, you can use the regex re module to perform regular expression operations like replace all occurrences of strings. The re.sub() function is
🌐
Python.org
discuss.python.org › python help
Selective replacement of matching text in a string? - Python Help - Discussions on Python.org
January 2, 2024 - I’ve having to deal with 1000’s of rows of strings that that can take any of the following form: a single word a string of words a string of words separated by a delimiter (in this case \\) I need to be able to replace all instances of matching text with another value, being sure not to ...
🌐
Sololearn
sololearn.com › en › Discuss › 2541803 › solved-why-replaceall-method-does-not-work-on-sl
[SOLVED] Why replaceAll method does not work on SL
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Codecademy Forums
discuss.codecademy.com › web development
"replaceAll is not a function". Is that so? - Web Development - Codecademy Forums
February 17, 2023 - Why do you think I see this weird message “replaceAll is not a function”? It definitely is!
🌐
Enterprise DNA
blog.enterprisedna.co › ways-to-replace-a-string-in-python
Python String replace() Method Tutorial
Learn data and AI skills on the platform, bring us in on a project, or run a managed Omni Command Centre. 220K+ professionals trained, 1,500+ companies impacted globally.