I have to search through a list and replace all occurrences of one element with another. So far my attempts in code are getting me nowhere, what is the best way to do this?<
I know this is a very old question and there's a myriad of ways to do it. The simpler one I found is using numpy package.
numpy
import numpy arr = numpy.asarray([1, 6, 1, 9, 8]) arr[ arr == 8 ] = 0 # change all occurrences of 8 by 0 print(arr)