Kemal Diri writes:

 > In my opinion, if I can get sum of the list, I should get avg also
 > in a same way.

And later:

 > The reason to propose this evolution is basically,

 >  *   If I can do sum(list) and len(list), would be better to do
 >      avg(list) (since I know sum and len of my list),

The standard response is "do it yourself":

    def avg(iterable):
        return sum(a:=tuple(iterable))/len(a)

If you don't need it to work on iterators, then you don't need to
mess with the temporary tuple.  "Walrus" operator requires Python 3.8.

 >  *   No need to import a library for this basic operation (even it
 >      costs nothing) so I won't consume a line.

That's not a reason that will get sympathetic hearing in Python, since
the defining expression is so short and obvious.  But you deserve a
more careful response.

First, Python would likely spell it "average" or "mean" nowadays, not
"avg".  Short Unix-style names such as "int", "dict", "len", and "dir"
are somewhat in disfavor (though obviously not enough so to change
the existing ones!)

Second, in principle, the implementers of Python disagree with your
opinion.  One reason is that sum is in some sense more primitive than
average (you needn't prefer this sense, but some people do).  Another
is that average is not well-defined for integers because Python has
two division operators.  Another is that there are a number of builtin
types that implement "+" and it makes sense to implement sum but not
average for several of them.  Finally, once you have one, the other is
trivial to implement (modulo the issue of integer division), so the
principle of parsimony of builtins motivates against adding average
since we already have sum.  Again, you're free to disagree that any or
all of these reasons is compelling, but be aware that this suggestion
is *extremely* unlikely to be implemented in Python.

By the way, for floats it's more accurate to compute average with
statistics.mean than with sum/len (which is almost certainly how it
would be implemented as a builtin):

>>> from statistics import mean
>>> sum([1e16,1,1])/3 == 1e16/3        # surprise!
True
>>> mean([1e16,1,1]) == 1e16/3
False

Regards,
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/E74TRAK5AX6SA6MD3XIPBJ24EC6PIKS3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to