Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Replace an item in a python list

# Replace Values in a List using Slicing
  
# define list
l = ['Hardik', 'Rohit', 'Rahul', 'Virat', 'Pant']
  
# find the index of Rahul
i = l.index('Rahul')
  
# replace Rahul with Shikhar
l = l[:i]+['Shikhar']+l[i+1:]
  
# print list
print(l)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Replace #item #python #list
ADD COMMENT
Topic
Name
2+3 =