How To Replace Number In List Python

Source URL: https://www.quora.com/Python-list-how-can-I-replace-certain-items-of-the-list

Language: python

Created on: 2021-03-01 08:08:25

>>> numbers = [1 , 2, 3, 4, 4, 6] # a normal python list 
>>> numbers[4] = 5 # replace the redundant item (5th item) 
>>> numbers 
[1, 2, 3, 4, 5, 6] 
Answer (1 of 17): If you know the index of the item that you want change , then do this: [code]a_list = ["a","b","c"] a_list[2] = "z" #new list will be like ["a","b","z"] [/code]But if you dont know the index of the item that you want to change then you have to do a “linear search": [code]a_lis...
content_copy