Automatic Histogram
Start Timer
0:00:00
Given a list of integers called dataset, write a function called automatic_histogram to automatically generate a dictionary representing a histogram of the data set with x bins uniformly distributed over the values.
Note: You should not include any bins that have zero values in them in your dictionary.
Note: Do NOT use numpy or pandas.
Example:
Input:
x = 3
dataset = [1,2,2,3,4,5]
Output:
automatic_histogram(dataset, x) -> {'1-2': 3, '3-4': 2, '5': 1}
Explanation:
x = 3 so our dictionary should have three entries
- The values
1and2are mapped to the first index of the histogram, so we count the values[1,2,2]ofdatasetas{'1-2': 3} - The values
3and4are mapped to the second index of the histogram, so we count[3,4]as{'3-4': 2} - The value
5is mapped to the third and final index of the histogram, so we count the single value of[5]in the dataset as{'5': 1}
.
.
.
.
.
.
.
.
.
Comments