C M Caine wrote:
Thank you for the clarification, bob.
For any future readers of this thread I include this link[1] to effbot's
guide on lists, which I probably should have already read.
My intention now is to modify list contents in the following fashion:
for index, value in enumerate(L):
L[0] = some_func(value)
Is this the standard method?
[1]: http://effbot.org/zone/python-list.htm
Colin Caine
Almost. You should have said
L[index] = some_func(value)
The way you had it, it would only replace the zeroth item of the list.
Note also that if you insert or delete from the list while you're
looping, you can get undefined results. That's one reason it's common
to build a new loop, and just assign it back when done. Example would
be the list comprehension you showed earlier.
DaveA
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor