title: efficient way to change values in python
body: <p>I am looking for an efficient way to update certain values. The current data structure I am using is a list, but I am open to other suggestions if they are faster. </p>
  
  <p>I'd like to find all values that match <code>0</code>, and change those values to <code>1</code></p>
  
  <pre><code>L = [1 ,2, 1, 3, 4, 2, 0, 1, 0]
  index = [i for i, x in enumerate(L) if x == 0]
  index
  [6, 8]
  
  for x in index:
      L[x] = 1
  L
  [1, 2, 1, 3, 4, 2, 1, 1, 1]
  </code></pre>