I have a very large dictionary with entries of the form {(Tuple) : [int, int]}
. For example, dict = {(1.0, 2.1):[2,3], (2.0, 3.1):[1,4],...}
that cannot fit in memory.
I'm only interested in the top K values in this dictionary sorted by the first element in each key's value. If there a data structure that would allow me to keep only the largest K key-value pairs? As an example, I only want 3 values in my dictionary. I can put in the following key-value pairs; (1.0, 2.1):[2,3], (2.0, 3.1):[1,4], (3.1, 4.2):[8,0], (4.3, 4.1):[1,1]
and my dictionary would be: (3.1, 4.2):[8,0], (1.0, 2.1):[2,3], (2.0, 3.1):[1,4]
(in case of key-value pairs with the same first element, the second element will be checked and the largest key-value pair based on the second element will be kept)