Guided Project: how to sort results from the frequency table

Once we’ve created a frequency table that shows each category and its average number of ratings, how can we sort it? I cannot figure out how to turn it into a tuple without having to retype all the results.

freq_table_as_tuple = [(612.0, ‘Medical’), (7003, ‘Education’), (4004, ‘Catalogs’)]
sorted(freq_table_as_tuple)

1 Like

Hi Olga,

Your initial frequency table a dictionary, right?

Then, if you work in Python version 3.7+, you can sort your dictionary by value using the following code:

import operator
sorted_dict= dict(sorted(unsorted_dict.items(), key=operator.itemgetter(1)))