A snippet to sort a dictionary.

This was explained in-depth here, so I’m including the code snippet in this blog for my own convenience.

dictionary_values = {'a'; 3, 'b': 1, 'c': 2}
sorted_dictionary_values = sorted(dictionary_values.items(), key=lambda x: x[1])

As this now calls for a sorted list, sorted_dictionary_values will now be a list of lists, size N x 2 (N = number of entries, 2 = key and value). You can demonstrate it as follows:

for i in sorted_dictionary_values:
    print(f'Key {i[0]}: Value {i[1]}')

This returns:

Key b: Value 1
Key c: Value 2
Key a: Value 3

The COVID-19 Pandemic Hackathon