iteration doesn't seem to work ??

Ant antroy at gmail.com
Wed May 16 07:17:29 EDT 2007


On May 16, 9: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.

See the other reponse for the why. Here's another how, using list
comprehension.:

1 > v = ['123', '345', '', '0.3']
2 > v = [x if x else '3' for x in v]
3 > v
3 = ['123', '345', '3', '0.3']

Note that this replaces the list, so won't be appropriate for
modifying a list passed in from elsewhere.

--
Ant...

http://antroy.blogspot.com/





More information about the Python-list mailing list