Q:

Why can't I alter lists in this way?

I wanted to have a nice set all list elements to a default value function. The one I came up with doesn't work, but my second solution does. Can anyone tell me why it works one way but not the other?
First solution:
def set_all(the_list,value): #NOT doing anything
    for item in the_list:
        item = value

Second solution:
def set_all(the_list,value): #working as intended
    for i,item in enumerate(the_list):
        the_list[i] = value

A:

When you do:
for item in the_list:
    item = value

You're only re-assigning the name item to something else (value, specifically), but you are not touching the reference the_list[i] that the list has to the original item. 
Consequently, you don't actually touch the list, so it doesn't change.

You can look at it that way:
When you do for item in the_list, you create a new reference to the underlying object: item.
When you do item = value, you're changing that reference and pointing it to something else. But the other reference, the one the list has to the underlying object, remains unchanged. 
Of course, when you do the_list[i], you're actually changing that reference that the list has to the object, which is why it works.

