Sort with extra variables

Thomas Dybdahl Ahle lobais at gmail.com
Sat Mar 3 06:35:56 EST 2007


Den Sat, 03 Mar 2007 11:26:08 +0100 skrev Diez B. Roggisch:

>> Well, you'd have to define the function inside the sortMoves function,
>> as it is where the variables exists.
>> 
>> def sortMoves(board, table, ply, moves):
>>     def sortKey(move):
>>         return getMoveValue(board, table, ply, move)
>>     moves.sort(key=sortKey, reverse=True) return moves
>> 
>> Wouldn't that make it create the callable at each call?
> 
> Yes, it does. But it's only created _once_ per sortMoves-call, and
> afterwards doesn't affect performance.

Sure, but I'm having a LOT of sortMove calls ;)

> And no, it's not slower than you lambda version - they _should_ be
> equally fast, if not it's neglible.

Sure, but the lambda version was too slow also.

> And also doesn't affect sorting-performance.

I know, but the sorting itself is really not the problem, as the lists 
only contain 5-30 items.



More information about the Python-list mailing list