I got the following dictionary:
mydict = {
'foo': [1,19,2,3,24,52,2,6], # sum: 109
'bar': [50,5,9,7,66,3,2,44], # sum: 186
'another': [1,2,3,4,5,6,7,8], # sum: 36
'entry': [0,0,0,2,99,4,33,55], # sum: 193
'onemore': [21,22,23,24,25,26,27,28] # sum: 196
}
I need to efficiently filter out and sort the top x entries by the sum of the array.
For example, the Top 3 sorted and filtered list for the example above would be
sorted_filtered_dict = {
'onemore': [21,22,23,24,25,26,27,28], # sum: 196
'entry': [0,0,0,2,99,4,33,55], # sum: 193
'bar': [50,5,9,7,66,3,2,44] # sum: 186
}
I'm fairly new to Python, and tried it myself with chaining a sum and filter function on a lambda function, but struggled with the actual syntax.