[Tutor] Alan G Week 10 warmup assignment help
Alan Gauld
alan.gauld at btinternet.com
Sat Apr 2 04:08:04 EDT 2016
On 02/04/16 02:21, Daniella Sapozhnikova wrote:
> I changed the file to this:
> DATA = {2: 7493945,
> 76: 4654320,
...
> 153: 12074784,
> 8: 4337229}
>
> def iter_dict_funky_sum(data=DATA):
> funky = 0
> for key, value in data.iteritems():
> funky += value - key
> return funky
>
>
> however now pylint is returning:
> task_07.py:36: [W0102(dangerous-default-value), iter_dict_funky_sum]
> Dangerous default value DATA (__builtin__.dict) as argument
>
> how can I pass the dictionary into the function, since pylint considers the
> wway I'm doing it to be wrong?
>
I would drop the default value for the parameter.
( I suspect that Python doesn't like DATA as a default value
because it means you cant use the function anywhere DATA is
not defined. But I'm not sure about that)
Just use:
def iter_dict_funky_sum(data):
...
Then when you call the function pass in DATA as its argument:
iter_dict_funky_sum(DATA):
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list