Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to replace a string in py

# Replace a particular item in a Python list
a_list = ['aple', 'orange', 'aple', 'banana', 'grape', 'aple']
for i in range(len(a_list)):
    if a_list[i] == 'aple':
        a_list[i] = 'apple'
print(a_list)
# Returns: ['apple', 'orange', 'apple', 'banana', 'grape', 'apple']
Source by datagy.io #
 
PREVIOUS NEXT
Tagged: #replace #string #py
ADD COMMENT
Topic
Name
7+6 =