How to replace all None values with the string "Null" in a dictionary

Mike Meyer mwm at mired.org
Thu Oct 27 16:46:32 EDT 2005


"dcrespo" <dcrespo at gmail.com> writes:

> Hi all,
>
> How can I replace all None values with the string 'Null' in a
> dictionary?

Iterate over everything in the dictionary:

for key, item in mydict.items():
    if item is None:
       mydict[key] = 'Null'

       <mike

-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list