Cuenta cuántas veces se repite un elemento

Published by lllll in

Dada una lista, crea una función que devuelva un diccionario donde se indique cuántas veces se repitió cada elemento.

Ejemplos

count_repetitions(["cat", "dog", "cat", "cow", "cow", "cow"]) ➞ { cow: 3, cat: 2, dog: 1 }

count_repetitions([1, 5, 5, 5, 12, 12, 0, 0, 0, 0, 0, 0]) ➞ { 0: 6, 5: 3, 12: 2, 1: 1 }

count_repetitions(["Infinity", "null", "Infinity", "null", "null"]) ➞ { "null": 3, "Infinity": 2}

Notas

N/A