[SciPy-user] What can be improved ?
Stephen Waterbury
waterbug at pangalactic.us
Wed May 16 09:10:05 EDT 2007
fred wrote:
> Gael Varoquaux a écrit :
>> Hello Stef,
>>
>>
>> I prefer this construction:
>> for i, val in enumerate(vals):
>> if val == '':
>> vals[i] = '0'
>>
> My very 2 cents:
>
> if val == '':
> is equivalent to
> if not val:
>
> (string and list empty equal False)
... which leads to a more efficient form, using a list
comprehension:
vals = [v or '0' for v in vals]
Steve
More information about the SciPy-User
mailing list