I am trying to sort values that are inside a dictionary of lists and create a new list out of them. Here is the data:
{
'fbi': [229, 421, 586, 654, 947, 955, 1095, 1294, 1467, 2423, 3063, 3478, 3617, 3730, 3848, 3959, 4018, 4136, 4297, 4435, 4635, 4679, 4738, 5116, 5211, 5330, 5698, 6107, 6792, 6906, 7036],
'comey': [605, 756, 1388, 1439, 1593, 1810, 1959, 2123, 2506, 3037, 6848],
'hillary': [14, 181, 449, 614, 704, 1079, 1250, 2484, 2534, 2659, 3233, 3374, 3488, 3565, 4076, 4756, 4865, 6125, 7109]
}
What I am trying is to find the 20 smallest values in these and get a list of their corresponding keys. For example, the first three least values are 14(hillary), 181(hillary) and 229(fbi). Therefore, how can I get a list like this:
['hillary', 'hillary', 'fbi']
All values will always be different. Also, all the values in the list are sorted, from ascending to descending.
Here is what I have tried:
for m in range(1,20):
for i in sort_vals.values():
if i[0] < a[0]:
a[0] = i[0]
This gives me the least value but not any other as after one iteration, the least value is always the same. I guess if I can delete that particular value it will be helpful. Can't think of anything else. Thanks!