Frequency of Numbers
Develop a Python application that will randomly select n integers from 1 to 9 and will count the number of occurrence of the numbers without using the Counter from collections library.
Sample Output:
How many numbers?: 7
[2, 6, 8, 2, 1, 1,6]
2-2
2-6
1-8
2-1
from random import randint
count = int(input("How many numbers?: "))
array = [randint(1, 9) for i in range(count)]
print(array)
dictionary = {}
for i in range(count):
if(array[i] in dictionary):
dictionary[array[i]] += 1
else:
dictionary[array[i]] = 1
print(dictionary)
Comments
Leave a comment