On 4/26/2010 10:19 PM, Dave Angel wrote:
Note also that if you insert or delete from the list while you're
looping, you can get undefined results.
The results are not undefined. They m,ight be unexpected, but that is
due to an invalid assumption.
The behavior is explained in section 7.3
On 04/27/10 12:19, Dave Angel wrote:
> 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.
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):
On 26 April 2010 23:45, Alan Gauld wrote:
>
> "C M Caine" 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)
Yes, I do
>> Is this the stand
>> What other strange behaviour should I expect from for loops?
>
> You should read up on immutable data types like strings and tuples.
> Start with [1].
>
> Greets
> Sander
>
> [1] http://docs.python.org/reference/datamodel.html
>
Thank you kindly for your reply, I'll be sure to read up on it.
C
"C M Caine" 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
On 26 April 2010 21:38, C M Caine wrote:
> Why does this not work:
L = [' foo ','bar ']
for i in L:
> i = i.strip()
str.strip() _returns_ a *new* string and leaves the original string
alone. The reason being that string are immutable so can not be
changed.
>>> s1 = ' foo '
>>> s1[1
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(v
On 4/26/2010 3:38 PM, C M Caine wrote:
Why does this not work:
By "work" you mean "do what I want it to do".
>>> L = [' foo ','bar ']
>>> for i in L:
i = i.strip()
This creates a new local variable named i. It does not affect L. This
has nothing to do with loops nor is it strange behav