I have a dictionary dict. For each key in dict, there is a list, that has two items in it. One is another dictionary, the other is an integer.

```
dict = {
    'hello' : [
      {
         'blah' : 1,
         'dodo' : 2
      },
      3
    ],
    'world' : [
      {
         'foo' : 7,
         'bar' : 1
      },
      8
    ]
 }

```

I want to sort the dictionary dict on the second item in the list, the integer. And then remove the first 'n' keys from the dictionary. Is there any way to do it? The sorted function works only on lists.

Here is the function I'm trying to do this in.

```
def create_inverted_index(inverted_index, corpus_tokens, corpus_files):
for file_tokens in corpus_tokens:
    file_id = corpus_files[file_tokens[0]]
    for token in file_tokens[1]:
        if token in inverted_index.keys():
            inverted_index[token][1] += 1
            if file_id in inverted_index[token][0].keys():
                inverted_index[token][0][file_id] += 1
            else:
                inverted_index[token][0][file_id] = 1
        else:
            inverted_index[token] = [{file_id : 1}, 1]

```