I have a list of random numbers in no specific order. Is there a way to count the number of times each number can be found in the list, and create a new list with these counts using a for loop? So not using an existing Python function. So, for example I have the list [9,18,13,9,6,6,16,6,17,10,15,16,13,11,13,8,20,6,18,11]. The output I want to have is [2,2,3,2,4 etc.].
A code I currently have is:
def countlisting(numberlist):
the_count = 0
q = 0
listofcount = []
for i in range(len(numberlist)):
if numberlist[i] == numberlist[q]:
the_count += 1
listofcount.append(the_count)
q += 1
return listofcount
the_numberlist = [9,18,13,9,6,6,16,6,17,10,15,16,13,11,13,8,20,6,18,11]
print(countlisting(the_numberlist))