else in list comp

Scott David Daniels Scott.Daniels at Acm.Org
Thu Jan 30 23:34:57 CET 2003


Cliff Wells wrote:
> I was looking for a fast, clean way of converting a single value in a
> list to a different value (specifically None to '').  It occurred to me
> to use a list comp and ...:
> 
Possibly:
     translate = {None:''}.get
     lst = ['mary', 'had', 'a', 'little', None]
     [translate(val, val) for val in lst]


-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list