How to calculate the average of the elements of a list with the function reduce() ... | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
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