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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -