iteration doesn't seem to work ??
stef
s.mientki at id.umcn.nl
Wed May 16 05:02:15 EDT 2007
hello Sean,
thanks very much for the explanation and solution.
cheers,
Stef Mientki
half.italian at gmail.com wrote:
> On May 16, 1:41 am, stef <s.mien... at id.umcn.nl> wrote:
>
>> hello,
>>
>> can someone tell me why the following iteration doesn't work,
>> and
>> how I should replace empty strings in a list with a default value.
>>
>> >>> v
>> ['123', '345', '', '0.3']
>> >>> for items in v:
>> ... if items=='':
>> ... items='3'
>> ...
>> >>>
>> >>> v
>> ['123', '345', '', '0.3']
>> >>>
>>
>> thanks,
>> Stef Mientki
>>
>
> Inside the loop, 'items' is no longer referencing the list...its a
> string.
>
>
>>>> v = ['123', '4', '567', '']
>>>> for i in v:
>>>>
> ... print type(i)
> ...
> <type 'str'>...
>
> This works
>
>
>>>> for j,i in enumerate(v):
>>>>
> ... if i=='':
> ... v[j] = '3'
> ...
>
>>>> v
>>>>
> ['123', '4', '567', '3']
>
>
> ~Sean
>
>
More information about the Python-list
mailing list