[Tutor] Alan G Week 10 warmup assignment help
Albert-Jan Roskam
sjeik_appie at hotmail.com
Sat Apr 2 05:59:33 EDT 2016
> To: tutor at python.org
> From: alan.gauld at btinternet.com
> Date: Sat, 2 Apr 2016 09:08:04 +0100
> Subject: Re: [Tutor] Alan G Week 10 warmup assignment help
>
> 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)
I thought this warning was about the use of mutable default arguments and its counterintuitive behavior: https://pythonconquerstheuniverse.wordpress.com/2012/02/15/mutable-default-arguments/
More information about the Tutor
mailing list