Answers for "how to replace string in list python"

0

how to replace string in list python

Use str. replace() to replace a string in a list
strings = ["a", "ab", "aa", "c"]
new_strings = []
for string in strings:
new_string = string. replace("a", "1") Modify old string.
new_strings. append(new_string) Add new string to list.
print(new_strings)
Posted by: Guest on April-07-2021
-1

how to replace an element in a list python

my_list= [1, 2, 3, 4, 5]
# i want to replace the 4 with a 7
my_list[3]= 7
"""
the downside of this solution is that you have to
know the index of the element you want to replace
"""
Posted by: Guest on June-30-2021

Code answers related to "how to replace string in list python"

Python Answers by Framework

Browse Popular Code Answers by Language