Re: Tough sorting problem: or, I'm confusing myself
- From: david jensen <dmj.ccc@xxxxxxxxx>
- Date: Tue, 13 Apr 2010 04:25:33 -0700 (PDT)
On Apr 11, 9:39 pm, Raymond Hettinger <pyt...@xxxxxxx> wrote:
The overall algorithm looks about right.
The inner-loop could be tighted-up a bit.
And you could replace the outer sort with a heap.
best2 = {}
for i in itertools.combinations(range( 2**m), n-1):
scorelist = []
for j in range( 2**m ):
if j not in i:
k = tuple(sorted(i + (j,)))
scorelist.append((j, res[k][k.index(j)]))
best2[i] = heapq.nlargest(2, scorelist,
key=operator.itemgetter(1))
Raymond
Thanks for the ideas... I should have seen the k = tuple(sorted(i +
(j,))). I'm not sure a heap will help much, and at least to me,
doesn't improve readability.
Thanks for taking a look, I appreciate it!
David
.
- Follow-Ups:
- Re: Tough sorting problem: or, I'm confusing myself
- From: Raymond Hettinger
- Re: Tough sorting problem: or, I'm confusing myself
- References:
- Tough sorting problem: or, I'm confusing myself
- From: david jensen
- Re: Tough sorting problem: or, I'm confusing myself
- From: Raymond Hettinger
- Tough sorting problem: or, I'm confusing myself
- Prev by Date: Re: curious about python version numbers
- Next by Date: Re: Tough sorting problem: or, I'm confusing myself
- Previous by thread: Re: Tough sorting problem: or, I'm confusing myself
- Next by thread: Re: Tough sorting problem: or, I'm confusing myself
- Index(es):