Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

replace in lists python

# 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 #lists #python
ADD COMMENT
Topic
Name
9+8 =