I was thinking this question should be asked on SO, but I was not able to find it somehow(Let me know in the comment section if there was one, i will delete this post)
It has came to my attention that when we do list replacement, it only works if we are loop through the list by index. Why?
myList = ['a','b','c','d','e']
for item in myList:
if item == 'a':
item = 's'
print("First loop:",myList) //It prints ['a','b','c','d','e']
for i in range(len(myList)):
if myList[i] == 'a':
myList[i] = 's'
print("Second loop:",myList) //It prints ['s','b','c','d','e']
I have tried to read the python control flow documentation: https://docs.python.org/3/tutorial/controlflow.html but it does not really answer my question.