Can you explain to me why this code does not change the value of each element in the list?
li = [3,4,5]
for elm in li:
elm = 1
print(li)
No, it does not. it changes the value of the elm
variable. To change the value of the list element you have to use following code.
li = [3,4,5]
for i in range(len(li)):
li[i] = 1
print(li)