-2
Serv = [0,1,1,0,9,7]
The most repeated items on the list are 0 and 1, but I couldn’t think of anything I could do to get this.
I tried to fix the first element,:
sound = [2,2,2,2,1,1] and definitely n know how to proceed with this to reach final = [0,1].
def mais_requisitados(serv):
final = []
som = []
for i in range(0,len(serv),1):
b = 0
som.append(b)
for i in serv:
for j in range(0,len(serv),1):
if serv[j] == i:
som[j] += 1
return print(final)
Is there any other more trivial way to do it? I haven’t seen a dictionary yet, but if there’s no other way I’ll give a study in a dictionary
– Moreira
@Moreira You can also use a list where the index represents the number and value, the amount of times it appears, but this method generates very large lists. On your list
serv
given as an example[2, 2, 0, 0, 0, 0, 0, 1, 0, 1]
. So just take the indexes of the largest element.– Murgalha