Re: Define key in nlargest() of heapq?

2007-11-13 Thread Duncan Booth
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 valu

Re: Define key in nlargest() of heapq?

2007-11-12 Thread Davy
Hi Raymond, Your code work well, thank you :) Best regards, Davy On Nov 13, 11:33 am, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > On Nov 12, 6:56 pm, Davy <[EMAIL PROTECTED]> wrote: > > > I have a dictionary with n elements, and I want to get the m(m<=n) > > keys with the largest values. > >

Re: Define key in nlargest() of heapq?

2007-11-12 Thread Raymond Hettinger
On Nov 12, 6:56 pm, Davy <[EMAIL PROTECTED]> wrote: > 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

Define key in nlargest() of heapq?

2007-11-12 Thread Davy
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]. How to do thi