id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

gaurav1780@gmail.com 04_lists > frequency_table
prev  |  next  |  chance

A frequency table is defined as a table containing each distinct item in a set and its corresponding number of occurrences. Define a function that when passed an integer array, returns the frequency table. The items should occur in order of their first occurrences in the original array. Because of the inability of codingbat to process mutli-dimensional arrays, the table should be an array of string objects, where each string represents the item and its frequency separated by a comma and a space (", ").


frequency_table([10, 70, 20, 70]) → ['10, 1', '70, 2', '20, 1']
frequency_table([5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) → ['5, 14']
frequency_table([1, 2, 3, 4, 1, 2, 3, 4, 4, 3, 2, 1, 1, 3, 2, 4, 4, 2, 3, 1, 5]) → ['1, 5', '2, 5', '3, 5', '4, 5', '5, 1']

...Save, Compile, Run (ctrl-enter)

def frequency_table(data):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 4 Post-solution available

Copyright Nick Parlante 2017 - privacy