In: Computer Science
The output of the function is a dictionary whose keys represent the bins and whose values are ints indicating the number of data items in each bin. How you represent the keys is up to you - there are several acceptable approaches, but care should be taken to use a structure that is compatible
I have included my code and screenshots in this answer. In case, there is any indentation issue due to editor, then please refer to code screenshots to avoid confusion.
------------------main.py---------------
def get_binned_data(inp_list): #Reads data creates bins and
counts number of values in each bin
binned_data = dict() #empty dictionary for creating
bins
for key in inp_list:
if key not in binned_data.keys():
#if key not in dict, then add and initialize t0 1
binned_data[key]
= 1
else:
binned_data[key]
= binned_data[key] + 1 # if key in dict, increment its count
return binned_data # return the binned_data
dictionary
list_of_input = [1, 4, 1, 1, 1, 1, 5, 3, 5, 4, 3, 7] #input list
for integers
print("\n List: ", list_of_input) #print input list
data = get_binned_data(list_of_input) #get binned data
dictionary
print("\n Output Dictionary : \n", data) # print the binned data
with counts
------------------Screenshot main.py---------------

------------------Output---------------

------------------------------------------
I hope this helps you,
Please rate this answer if it helped you,
Thanks for the opportunity