mapping None values to ''
Steven Bethard
steven.bethard at gmail.com
Sun Jun 18 23:09:49 EDT 2006
Scott David Daniels wrote:
> Roberto Bonvallet wrote:
>> imho <certo at comeno.it>:
>>> map(lambda x:"" , [i for i in [a,b,c] if i in ("None",None) ])
>> You don't need map when using list comprehensions:
>> ["" for i in [a, b, c] if i in ("None", None)]
>>
> More like:
>
> [(i, "")[i in ("None", None)] for i in [a,b,c]]
Or in Python 2.5:
Python 2.5a2 (trunk:46491M, May 27 2006, 14:43:55) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 0
>>> b = None
>>> c = None
>>> a, b, c = ('' if x in (None, 'None') else x for x in (a, b, c))
>>> a, b, c
(0, '', '')
But someone please shoot me if I ever use something like that in
production code. ;)
STeVe
More information about the Python-list
mailing list