Hi, I'm doing a program that has a list of repeated and messy colors. I want to know which of those colors is the most repeated and in its case return the most repeated color and the number of times. There is a particularity, if there are several colors with the maximum number the priority of the list would be: blue, red, green and yellow.
To be able to do it I have thought about creating a function with 2 lists:
1 List with disordered and repeated colors.
2. List with priority.
This way I can go through the elements of list 2 and see how many times it repeats.
My program started like that but I got stuck and I do not know how to continue it:
def color_frecuente(lista):
lista2 =["azul","rojo","verde","amarillo"]
print lista2
contador = 0
for i in lista2:
for j in colores:
if i == j:
contador += 1
return (i,contador)
# bloque principal
colores = ['azul', 'rojo', 'verde', 'verde', 'verde', 'rojo', 'verde', 'verde', 'azul', 'amarillo', 'azul',
'azul', 'verde', 'verde', 'verde', 'amarillo']
print color_frecuente(colores)
Can you help me out?
Thank you.