Sort with extra variables

MonkeeSage MonkeeSage at gmail.com
Sat Mar 3 01:27:47 CET 2007


On Mar 2, 5:51 pm, Thomas Dybdahl Ahle <lob... at gmail.com> 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

Regards,
Jordan




More information about the Python-list mailing list