Sort with extra variables

MonkeeSage MonkeeSage at
Sat Mar 3 01:27:47 CET 2007

On Mar 2, 5:51 pm, Thomas Dybdahl Ahle <lob... at> wrote:
> I guess the thing is that I'd have to create a new callable no matter
> how, as it is the only way to bring the extra variables into the getValue
> function when called by sort.

Yes, but you don't have to create it every time you call sortMoves...

def sortKey(move):
    return getMoveValue(board, table, ply, move)

def sortMoves(board, table, ply, moves):
    moves.sort(key=sortKey, reverse=True)
    return moves


More information about the Python-list mailing list