Just noticed something when I was mutating a list in python:
my_list = ['a','b','c','d','e']
Example 1
for letter in my_list:
if letter == 'c':
letter = 'x'
Example 2
for i in range(len(my_list)):
if my_list[i] == 'c':
my_list[i] = 'x'
Result 1
my_list = ['a','b','c','d','e']
Result 2
my_list = ['a','b','x','d','e']
So my question is it 'letter' not a direct reference to an element in 'my_list' ? Whats the difference between the two loops?