How to calculate the average of the elements of a list with the function reduce() ... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to calculate the average of the elements of a list with the function reduce() ...

How to calculate the average of the elements of a list "with the function reduce()", without having to divide in the end the sum with the number of elements A = [2, 4, 5, 1, 10, 5, 2, 5, 7] prom = reduce(lambda x , y : x + y, A) / len(A) print (prom)

14th Mar 2017, 1:25 AM
Javier I. Rivera R.
Javier I. Rivera R. - avatar
2 Answers
0
@Maria Isabel, el código si usa una función.. es una función anónima que de realiza con la palabra clave lambda.. Lambda x , y : x + y .. es la función.
17th Mar 2017, 7:25 PM
Javier I. Rivera R.
Javier I. Rivera R. - avatar
- 1
Le falta definir la función.
14th Mar 2017, 11:20 PM
Maria Isabel
Maria Isabel - avatar