This loop has two iteration variables because items returns a list of tuples and key, val is a tuple assignment that successively iterates through each of the key-value pairs in the dictionary.
To do this, we first make a list of tuples where each tuple is (value, key). The items method would give us a list of (key, value) tuples, but this time we want to sort by value, not key. Once we have constructed the list with the value-key tuples, it is a simple matter to sort the list in reverse order and print out the new, sorted list.
By carefully constructing the list of tuples so that the value is the first element of each tuple and the key is the second element, we can sort our dictionary contents by value.
Write code to create a list called โlstโ and add the key-value pairs of dictionary d to list lst as tuples. Sort list lst by the values in descending order.