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 a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training
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
Selective replacement of matching text in a string?
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 ... More on discuss.python.org
🌐 discuss.python.org
16
0
January 2, 2024
"replaceAll is not a function". Is that so?
Why do you think I see this weird message “replaceAll is not a function”? It definitely is! More on discuss.codecademy.com
🌐 discuss.codecademy.com
0
0
February 17, 2023
Python: How can I replace one specific character on a string while leaving the rest of the string as it was?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
12
6
October 18, 2023
🌐
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
October 31, 2025 - 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 ...
🌐
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…
🌐
Real Python
realpython.com › replace-string-python
How to Replace a String in Python – Real Python
January 15, 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.
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 ...
🌐
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
May 25, 2026 - 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
The original string is left unchanged. const paragraph = "This dog's name is just Dog! Yes, that is the name."; console.log(paragraph.replaceAll("name", "nickname")); // Expected output: "This dog's nickname is just Dog! Yes, that is the nickname." console.log(paragraph.replaceAll(/\bis\b/g, "was")); // Expected output: "This dog's name was just Dog!
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-replace
Python String replace() Method - GeeksforGeeks
1 week ago - 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 from world-class experts to drive impactful change in your career, your business, and your world. Ready to start learning?
🌐
Sanfoundry
sanfoundry.com › python-program-replace-occurrences-string
Python Program to Replace All Occurrences of ‘a’ with $ in a String - Sanfoundry
May 30, 2022 - This is a Python Program to replace all occurrences of ‘a’ with ‘$’ in a string. Problem Description The program takes a string and replaces all occurrences of ‘a’ with ‘$’. Problem Solution 1. Take a string and store it in a variable. 2. Using the replace function, replace ...