On Nov 12, 10:07 am, Davy <[EMAIL PROTECTED]> wrote: > Hi all, > > I have a dictionary with n elements, and I want to get the m(m<=n) > keys with the largest values. > > For example, I have dic that includes n=4 elements, I want m=2 keys > have the largest values) > dic = {0:4,3:1,5:2,7:8} > So, the the largest values are [8,4], so the keys are [7,0]. > > Is there any fast way to implement this algorithm? > Any suggestions are welcome! > > Best regards, > Davy
Have a look at http://docs.python.org//lib/module-heapq.html -- http://mail.python.org/mailman/listinfo/python-list