[Tutor] forcing the None values of a dictionary
d at davea.name
Wed Oct 3 22:41:31 CEST 2012
On 10/03/2012 03: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:
> 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
Hard to tell what you might have overlooked. Does the function
correctly implement the specification you didn't tell us about?
There's no English word "destrictively" so I'm not sure what you're
asking. The function certainly doesn't return a new dictionary, it
returns the same one passed in. In other words, it mutates itself in
place. By convention, it should return None (which would happen if you
had no return statement).
More information about the Tutor