Sort with extra variables
Diez B. Roggisch
deets at nospam.web.de
Sat Mar 3 05:26:08 EST 2007
> 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.
And no, it's not slower than you lambda version - they _should_ be
equally fast, if not it's neglible. And also doesn't affect
sorting-performance.
Diez
More information about the Python-list
mailing list