BartC writes: > On 24/03/2016 14:08, Jon Ribbens wrote: >> On 2016-03-24, BartC wrote: >>> I'd presumably have to do: >>> >>> for i in range(len(L)): >>> L[i]=0 >> >> That's kind've a weird thing to want to do; > > The thing I'm trying to demonstrate is changing an element of a list > that you are traversing in a loop. Not necessarily set all elements to > the same value.
You understand correctly, but it may be more natural in practice to write it this way: for k, item in enumerate(them): them[k] = f(item) I _think_ I might write it that way even when "f(item)" does not depend on the old value at all, but I don't expect to be in that situation. -- https://mail.python.org/mailman/listinfo/python-list