Re: Order by value in dictionary

2007-10-18 Thread Amit Khemka
On 10/17/07, Abandoned <[EMAIL PROTECTED]> wrote: > Very very thanks everbody.. > > These are some method.. > Now the fastest method is second.. > > 1 === > def sortt(d): > items=d.items() > backitems=[ [v[1],v[0]] for v in items] > backitems.sort() > #boyut=len(backitems) >

Re: Order by value in dictionary

2007-10-18 Thread Duncan Booth
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > Without throwing away 500 items: > > def sortt(d): > sorted_items = sorted(d.iteritems(), > key=operator.itemgetter(1), > reverse=True) > return map(operator.itemgetter(0), sorted_ite

Re: Order by value in dictionary

2007-10-17 Thread Abandoned
I tried these: def largest_sort(d, n): return sorted(d, key=d.__getitem__, reverse=True)[:n] def largest_heap(d, n): return heapq.nlargest(n, d, d.__getitem__) def sortt(d): sorted_items = sorted((item[1], item[0]) for item in d.iteritems(), reverse=True)

Re: Order by value in dictionary

2007-10-17 Thread Peter Otten
Abandoned wrote: > These are some method.. > Now the fastest method is second.. Your four functions return three different results for the same input. First make sure it's correct, then make it faster (if necessary). Here are two candidates: def largest_sort(d, n): return sorted(d, key=d.__

Re: Order by value in dictionary

2007-10-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Oct 2007 08:09:50 -0700, Abandoned wrote: > Very very thanks everbody.. > > These are some method.. > Now the fastest method is second.. Maybe because the second seems to be the only one that's not processing the whole dictionary but just 500 items less!? You are building way too muc

Re: Order by value in dictionary

2007-10-17 Thread Abandoned
Very very thanks everbody.. These are some method.. Now the fastest method is second.. 1 === def sortt(d): items=d.items() backitems=[ [v[1],v[0]] for v in items] backitems.sort() #boyut=len(backitems) #backitems=backitems[boyut-500:] a=[ backitems[i][1] for i in rang

Re: Order by value in dictionary

2007-10-17 Thread Diez B. Roggisch
George Sakkis wrote: > On Oct 17, 10:06 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Diez B. Roggisch wrote: >> > Abandoned wrote: >> >> >> Hi.. >> >> I have a dictionary like these: >> >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 >> >> element >> >> I want to sort

Re: Order by value in dictionary

2007-10-17 Thread George Sakkis
On Oct 17, 10:06 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > > Abandoned wrote: > > >> Hi.. > >> I have a dictionary like these: > >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 > >> element > >> I want to sort this by value and i want to fir

Re: Order by value in dictionary

2007-10-17 Thread cokofreedom
On Oct 17, 4:06 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > > Abandoned wrote: > > >> Hi.. > >> I have a dictionary like these: > >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 > >> element > >> I want to sort this by value and i want to firs

Re: Order by value in dictionary

2007-10-17 Thread Diez B. Roggisch
Diez B. Roggisch wrote: > Abandoned wrote: > >> Hi.. >> I have a dictionary like these: >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 >> element >> I want to sort this by value and i want to first 100 element.. >> Result must be: >> [b, a, d, c .] ( first 100 element)

Re: Order by value in dictionary

2007-10-17 Thread cokofreedom
On Oct 17, 3:39 pm, Abandoned <[EMAIL PROTECTED]> wrote: > Hi.. > I have a dictionary like these: > a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 > element > I want to sort this by value and i want to first 100 element.. > Result must be: > [b, a, d, c .] ( first 100 elemen

Re: Order by value in dictionary

2007-10-17 Thread Diez B. Roggisch
Abandoned wrote: > Hi.. > I have a dictionary like these: > a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 > element > I want to sort this by value and i want to first 100 element.. > Result must be: > [b, a, d, c .] ( first 100 element) > > I done this using FOR and ITERA

Order by value in dictionary

2007-10-17 Thread Abandoned
Hi.. I have a dictionary like these: a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 element I want to sort this by value and i want to first 100 element.. Result must be: [b, a, d, c .] ( first 100 element) I done this using FOR and ITERATOR but it tooks 1 second and this i