I have a dictionary of dictionary as below:

```
ls = [{'0': {'1': '1','2': '0.5','3': '1'},'1': {'0': '0.2','2': '1','3': '0.8'},}]

```

I would like to select k-largest values with their keys for each key of dictionary (ls). I have written below commands. It just gives me the k-largest keys without their values.

**Python Code:**

```
import heapq
k=2
for dic in ls:
    for key in dic:
        print(heapq.nlargest(k, dic[key], key=dic[key].get))

```

**Output**

```
['2', '3']
['3', '1']

```

I need to have value of each selected key.
['https://Stackoverflow.com/questions/35994855', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6062233/']
* First of all, I just wanted to check why you have 

`ls = [{'0': {'1': '1','2': '0.5','3': '1'},'1': {'0': '0.2','2': '1','3': '0.8'},}]`

This is a list containing a dict, which doesn't match your description in the question.
* Here is a solution that uses dict comprehensions that should give you what you want :)

```
 def get_n_largest_vals(n, d):
     x = {key: heapq.nlargest(len, map(int, d[key])) for key in d}
     return {key: map(str, x[key]) for key in x}

```

Here it is being used for your problem:

```
ls = [{'0': {'1': '1','2': '0.5','3': '1'},'1': {'0': '0.2','2': '1','3': '0.8'},}]
d = ls[0]
get_n_largest_vals(2, d)
>>> {'0': ['3', '2'], '1': ['3', '2']}

```
How about:

```
from operator import itemgetter
for d in ls:
    for key, d2 in d.items():
        print(dict(heapq.nlargest(k, d2.items(), key=itemgetter(1))))

```

Notice that your *values* are still *strings* so they'd be lexically ordered, which is not what you want, because `'2' > 12'` And the dictionary is not ordered!