While looping over a list in Python, I was unable to modify the elements without a list comprehension. For reference:
li = ["spam", "eggs"]
for i in li:
i = "foo"
li
["spam", "eggs"]
li = ["foo" for i in li]
li
["foo", "foo"]
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.