title: Can't modify list elements in a loop
body: <p>While looping over a list in Python, I was unable to modify the elements without a list comprehension.
  For reference:</p>
  <pre><code>li = [&quot;spam&quot;, &quot;eggs&quot;]
  for i in li:
      i = &quot;foo&quot;
  
  li
  [&quot;spam&quot;, &quot;eggs&quot;]
  
  li = [&quot;foo&quot; for i in li]
  li 
  [&quot;foo&quot;, &quot;foo&quot;]
  </code></pre>
  <p>So, why can't I modify elements through a loop in Python? There's definitely something I'm missing, but I don't know what. I'm sure this is a duplicate, but I couldn't find a question about this, and if there is a link, that would be more than enough.</p>