[Tutor] forcing the None values of a dictionary
bgailer at gmail.com
Wed Oct 3 23:00:35 CEST 2012
On 10/3/2012 3:59 PM, Brannon, Terrence wrote:
> I'm wondering if there is something I overlooked for this function I
> wrote... and also whether it could've been done destrictively instead
> of returning a new dictionary:
I don't understand your question. Could you clarify? What does
"destrictivel" mean? Why do you say it is returning a new dictionary (it
simply returns the modified input dictionary)?
Since d is mutable, the function changes it "in place". You could drop
the return statement and call the function thusly:
d = someDictionary
> *def* dictNoneValueTo(d, new_value=''):
> *"""force None values in a dictionary to a default value"""*
> *for* k *in* d:
> *if* d[k] *is* *None*:
> d[k] = new_value
> *return* d
For what its worth please inform your lawyers that I do not read or heed
any lengthy legalese at the end of emails. I think they do more to
irritate recipients than to protect anything.
Be warned: this message has no intention to do anything but inform. You
may do anything with it you like. So there.
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor