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).



-- 

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to