mapping None values to ''
Gerard Flanagan
grflanagan at yahoo.co.uk
Sun Jun 18 08:45:23 EDT 2006
micklee74 at hotmail.com wrote:
> hi
> i wish to map None or "None" values to "".
> eg
> a = None
> b = None
> c = "None"
>
> map( <something> , [i for i in [a,b,c] if i in ("None",None) ])
>
> I can't seem to find a way to put all values to "". Can anyone help?
> thanks
a = [None, 'None', None]
def filtre(x):
if x is None or x == 'None':
return ''
else:
return x
assert map(filtre, a) == ['', '', '']
a = [1, 2, None, 'None', 3, 4]
assert map(filtre, a) == [1, 2, '', '', 3, 4]
More information about the Python-list
mailing list