FRECUENCIA LISTAS EN PYTHON
Publicado por Ian (3 intervenciones) el 21/10/2019 18:35:34
Hola a todos y gracias de antemano. Tengo el siguiente programa con una función llamada dice_freqs que toma como parámetro una lista y devuelve una lista de 6 elementos conteniendo la frecuencia de aparición de los números del 1 al 6, en este orden.
Por ejemplo:
input: [4,2,3,1,4,4,4,4,6,1,5,5]
output: [2, 1, 1, 5, 2, 1]
EL PROBLEMA EN EL CÓDIGO QUE TENGO ES QUE UNICAMENTE ME DEVUELVE [4] EN VEZ DE UNA LISTA CON LOS ELEMENTOS ORDENADOS DEL 1 AL 6 Y EN ELLOS EL NÚMERO DE REPETICIONES DE CADA UNO QUE APARECE EN LA LISTA
Por ejemplo:
input: [4,2,3,1,4,4,4,4,6,1,5,5]
output: [2, 1, 1, 5, 2, 1]
1
2
3
4
5
import functions
throws = [4,2,3,1,4,4,4,4,6,1,5,5]
frecs = functions.dice_freqs(throws)
print(frecs)
1
2
3
4
from collections import Counter
def dice_freqs(throws):
position = [(Counter(throws).most_common()[0][0])]
return(position)
EL PROBLEMA EN EL CÓDIGO QUE TENGO ES QUE UNICAMENTE ME DEVUELVE [4] EN VEZ DE UNA LISTA CON LOS ELEMENTOS ORDENADOS DEL 1 AL 6 Y EN ELLOS EL NÚMERO DE REPETICIONES DE CADA UNO QUE APARECE EN LA LISTA
Valora esta pregunta


0