You can do a list-comprehension:

test = ['path', 'name', 'user1', 'orig']

mylist = ['user' if 'user' in x else x for x in test]
# ['path', 'name', 'user', 'orig']
Answer from Austin on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 3136689 › find-and-replace-string-values-in-list
python - Find and replace string values in list - Stack Overflow
I got this list: words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really'] What I would like is to replace [br] with some fantastic value similar to and thus getting a new ...
Discussions

Python- how to replace characters in a list item in a list - Stack Overflow
I am a beginner in python and am trying to tackle this problem and just cannot get my output right. I am trying to change the value of an item in a list and pass the item to a new list. mylist = [... More on stackoverflow.com
🌐 stackoverflow.com
December 19, 2018
How to Replace Characters in a List in Python? - Stack Overflow
And that means if you just print out ''.join(list), So, you're going to get a 14-character string with an invisible character, then 00SFFF0001FF, then a carriage return, not the 56-character string you wanted. ... Save this answer. ... Show activity on this post. The first problem is that replace ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to replace a specific character in every element of a list - Stack Overflow
I have a list in Python which contains the number of posted tweets per user profile. For example: list = ['142', '1567', '153K', '32', '10', '50'] As you can see, when the number is very high (... More on stackoverflow.com
🌐 stackoverflow.com
September 26, 2017
python - How to replace a character with another character in a list of string - Stack Overflow
I have the following list of strings: a = ['1234!zf', '5678!ras', 'abcd!ggt', 'defg!z', 'hijk!', 'lmnk!reom'] I want to replace the 4th character with another character (the character will always ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 72378766 › how-to-replace-a-character-within-a-string-in-a-list
python - How to replace a character within a string in a list? - Stack Overflow
Then you can call this function like the following to get the result. ... Save this answer. ... Show activity on this post. ... Here are a few examples of more complex replacements that you may find useful, e.g., replace everything that is not a word character:
🌐
Note.nkmk.me
note.nkmk.me › home › python
Extract and Replace Elements That Meet the Conditions of a List of Strings in Python | note.nkmk.me
May 19, 2023 - Replace strings in Python (replace, translate, re.sub, re.subn) List comprehensions offer a simpler alternative to the traditional for loop when creating new lists.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-replace-substring-in-list-of-strings
Replace substring in list of strings - Python - GeeksforGeeks
July 11, 2025 - map() function applies replace() to each string in the list without using explicit loops.
Top answer
1 of 3
4

The first problem is that replace doesn't change a string in-place, it just returns a new string. And you're ignoring that new string.

What you want is:

new_list = []
for x in list:
    new_list.append(x.replace("[","").replace("]","").replace('"','').replace(" ","").replace(",","").replace("[",""))

You can simplify that with translate, or use a different way of filtering out the characters like a comprehension or a filter call. But the result will be the same.


The bigger problem is that what you're trying to do doesn't make any sense. None of the elements in your list have a [, ], ", etc. character in them. You're probably confusing the string representation of the list with the list itself.

If you want to join the members of a list, or to produce any representation of the list other than the default repr, just explicitly join them. For example, this gets what you seem to want:

''.join(list)

… and this gets a different representation:

' and '.join(list)

… and this gets roughly the same thing as repr:

'[' + ', '.join(map(repr, list)) + ']'
2 of 3
3

Use str.join:

>>> lis = ["/x01", "/x30", "/x30", "/x53", "/x46", "/x46", "/x46", "/x30", "/x30", "/x30", "/x31", "/x46", "/x46", "/x0D"]
>>> ''.join(lis)
'/x01/x30/x30/x53/x46/x46/x46/x30/x30/x30/x31/x46/x46/x0D'

Looking at your code, I think you were trying to apply str.replace on str version of the list. But that would be a weird way to do this, better use str.join:

>>> str(lis)
"['/x01', '/x30', '/x30', '/x53', '/x46', '/x46', '/x46', '/x30', '/x30', '/x30', '/x31', '/x46', '/x46', '/x0D']"

The above string is just a representation of the list object.

>>> str(lis).replace("[","").replace("]","").replace(" ","").replace(",","").replace("'","")
'/x01/x30/x30/x53/x46/x46/x46/x30/x30/x30/x31/x46/x46/x0D'
Find elsewhere
🌐
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 - When replacing characters in a Python string, you should build logic into the code to manage edge cases so the code doesn’t break or return an error. Here is the overview of these scenarios. There’s only one best practice I’d recommend: keep it simple! This means stick with str.replace() for basic replacements; it’s what it’s designed for, and it’s quick. Use list comprehension when you really need more control over replacement, i.e., you can’t do it with str.replace().
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-replace-values-in-a-list-in-python
Replace Values in a List in Python - GeeksforGeeks
It works when the index of the element to be replaced is already known. ... This method checks every element in the list and replaces only those values that satisfy a given condition, while rebuilding the list in a single expression using list comprehension.
Published: January 12, 2026
🌐
Stack Overflow
stackoverflow.com › questions › 72925306 › how-to-replace-a-character-with-another-character-in-a-list-of-string
python - How to replace a character with another character in a list of string - Stack Overflow
There are multiple ways to do this, but string slicing is a good way to go. In this example, each string is sliced with the new character added at offset 4. Its built into a new list and then a slice encompassing the entire original list is ...
🌐
stataiml
stataiml.com › posts › 35_find_replace_string_python_list
Find and Replace Values in List in Python - stataiml
May 3, 2024 - You can find and replace string values in a list using a list comprehension or map() function in Python. new_list = [s.replace('old_string', 'new_string') for s in input_list] new_list = map(lambda s: str.replace(s, 'old_string', 'new_string'), ...
🌐
Stack Overflow
stackoverflow.com › questions › 51377422 › how-do-i-replace-a-character-in-a-list-with-a-character-in-a-different-list-in-p
How do I replace a character in a list with a character in a different list in python - Stack Overflow
July 17, 2018 - If I understood correctly, you want to replace a character that is given by a user with the next character of the alphabet. ... alphabet =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] wordlist = [] inputword = input("Please enter a string:") wordlist = list(inputword) if wordlist[0] == 'z': #print('Sorry, I do not know what to do for this case') idx = 0 new_word = alphabet[idx] print(new_word) else: idx = alphabet.index(wordlist[0]) new_word = alphabet[idx +1] print(new_word)
🌐
Stack Overflow
stackoverflow.com › questions › 26721850 › replace-characters-in-a-list
python - replace characters in a list - Stack Overflow
You dont need to map the letter to its blank in case of multiple occurances. ... Save this answer. ... Show activity on this post. You're iterating the whole list once with that in, then iterating it again with that for, the iterating it again with each index call.
🌐
FavTutor
favtutor.com › blogs › replace-character-string-python
Python Replace Character in String | FavTutor
October 6, 2021 - Below are 6 common methods used to replace the character in strings while programming in python. Slicing is a method in python which allows you to access different parts of sequence data types like strings, lists, and tuples. Using slicing, you can return a range of characters by specifying ...
🌐
TutorialsPoint
tutorialspoint.com › article › python-program-to-replace-all-characters-of-a-list-except-the-given-character
Python program to replace all Characters of a List except the given character
March 26, 2026 - The list is: ['P', 'Y', 'T', 'H', 'O', 'N', 'P', 'H', 'P'] The result is: ['P', '$', '$', '$', '$', '$', 'P', '$', 'P'] You can also achieve the same result using a traditional for loop ? characters = ['P', 'Y', 'T', 'H', 'O', 'N', 'P', 'H', 'P'] replace_char = '$' retain_char = 'P' result = [] for element in characters: if element == retain_char: result.append(element) else: result.append(replace_char) print("Original list:", characters) print("Modified list:", result)