Tough sorting problem: or, I'm confusing myself
david jensen
dmj.ccc at gmail.com
Tue Apr 13 07:25:33 EDT 2010
On Apr 11, 9:39 pm, Raymond Hettinger <pyt... at rcn.com> 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
More information about the Python-list
mailing list