python - store multiple integer values in one list and return best value pair -
i have following 3 integer values:
id # identifies pair entropy # gives entropy information len # basicly length of string now want store many of these values , select top 10 having highest entropy overall , length value on n
from collections import defaultdict d = defaultdict(list) id, entropy, len in generatevalues: d[id].append(entropy) d[id].append(len) # top 10 values can done?
you can top 10 values after you've constructed dictionary this. although there more efficient solution if find them construct dictionary if that's possible.
import heapq heapq.nlargest(10, (k k in d if d[k][1] > n), key=lambda k: d[k][0])
Comments
Post a Comment