[Tutor] For loop breaking string methods

Alan Gauld alan.gauld at btinternet.com
Tue Apr 27 00:45:58 CEST 2010

"C M Caine" <cmcaine at googlemail.com> wrote 

> My intention now is to modify list contents in the following fashion:
> for index, value in enumerate(L):
>    L[0] = some_func(value)

I think you mean:
      L[index] = some_func(value)

> Is this the standard method?

Or use a List copmprehension.

L = [some_func(value) for value in L]

I'd say nowadays that the comprehension was most common.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list