Question

In: Computer Science

The output of the function is a dictionary whose keys represent the bins and whose values...

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

Solutions

Expert Solution

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


Related Solutions

how to check if there are keys with the same values in a dictionary. python 3.0...
how to check if there are keys with the same values in a dictionary. python 3.0 for example: data = {'size': 4, 'entrance':(0, 0), 'exit':(0,0)} since the entrance and exit keys have the same value, i want the function to return None.
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values in the dictionary. For example: dict1 = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':4}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} dict2 = {300:{'s': 300}, 400:{'s': 100, 'g': 100, 'p': 100}, 500: {'s': 50 ,'m': 400, 'p':30, 'i': 50}, 600: {'s': 40, 'i': 400}, 700: {'m': 100, 'p': 50}} def dict_sum(db): should give output...
Python 3.7.4 ## Tombstones ''' A Grave is a dictionary with two keys: * 'Name': A...
Python 3.7.4 ## Tombstones ''' A Grave is a dictionary with two keys: * 'Name': A string value with the grave's occupant's name * 'Message': A string value with the grave's message ''' Grave = {'name': str, 'Message': str} ''' G1. Define the function `count_grave_all` that consumes a list of graves and produces an integer representing the number of characters needed to write all of the message of the grave. Include spaces and new lines. ''' ''' G2. Define the...
Using Python, create a function whose inputs are two matrices and whose output is the element...
Using Python, create a function whose inputs are two matrices and whose output is the element wise product of the two matrices.
Python The following dictionary contains the list of US states with their abbreviations as keys and...
Python The following dictionary contains the list of US states with their abbreviations as keys and full names as values: states = { 'AK': 'Alaska', 'AL': 'Alabama', 'AR': 'Arkansas', 'AS': 'American Samoa', 'AZ': 'Arizona', 'CA': 'California', 'CO': 'Colorado', 'CT': 'Connecticut', 'DC': 'District of Columbia', 'DE': 'Delaware', 'FL': 'Florida', 'GA': 'Georgia', 'GU': 'Guam', 'HI': 'Hawaii', 'IA': 'Iowa', 'ID': 'Idaho', 'IL': 'Illinois', 'IN': 'Indiana', 'KS': 'Kansas', 'KY': 'Kentucky', 'LA': 'Louisiana', 'MA': 'Massachusetts', 'MD': 'Maryland', 'ME': 'Maine', 'MI': 'Michigan', 'MN': 'Minnesota', 'MO': 'Missouri',...
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
Weight Lifting Make a dictionary where the keys are the names of weight lifting exercises, and...
Weight Lifting Make a dictionary where the keys are the names of weight lifting exercises, and the values are the number of times you did that exercise.(At least 5 exercises,be creative. Nobody should have same values) Use a for loop to print out a series of statements such as "I did 10 bench presses". Modify one of the values in your dictionary, to represent doing more of that exercise. Use a for loop to print out a series of statements...
Write a function that accepts a dictionary and produces a sorted list of tuples The dictionary...
Write a function that accepts a dictionary and produces a sorted list of tuples The dictionary looks like this: {‘US’: [{'Chicago, IL': ('2/1/2020 19:43', 2, 0, 0)}, {'San Benito, CA': ('2/3/2020 3:53', 2, 0, 0)}, {'Santa Clara, CA': ('2/3/2020 0:43', 2, 0, 0)}, {'Boston, MA': ('2/1/2020 19:43', 1, 0, 0)}, {'Los Angeles, CA': ('2/1/2020 19:53', 1, 0, 0)}, {'Orange, CA': ('2/1/2020 19:53', 1, 0, 0)}, {'Seattle, WA': ('2/1/2020 19:43', 1, 0, 0)}, {'Tempe, AZ': ('2/1/2020 19:43', 1, 0, 0)}], 'Australia'...
ising software pyton 3.5 Weight Lifting Make a dictionary where the keys are the names of...
ising software pyton 3.5 Weight Lifting Make a dictionary where the keys are the names of weight lifting exercises, and the values are the number of times you did that exercise.(At least 5 exercises,be creative. Nobody should have same values) Use a for loop to print out a series of statements such as "I did 10 bench presses". Modify one of the values in your dictionary, to represent doing more of that exercise. Use a for loop to print out...
Find a possible formula for the trigonometric function whose values are in the following table. x...
Find a possible formula for the trigonometric function whose values are in the following table. x 0 2 4 6 8 10 12 y 8 2 -4 2 8 2 -4 y =
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT