我有一个类Move,它有三个属性:newPos、oldPos和notation。符号是一个字符串。我生成了一个移动列表,我想检查它们的符号是否相同。做这件事最有可能的方法是什么?我能想到的最干净的解决办法是:
duplicateNotationMoves = []
for move in moves :
if len([m for m in moves if m.notation == move.notation]) :
duplicateNotationMoves.append(move)
它工作得很好,但它似乎效率低下,不太像Python。有没有一种更干净的方法来获取所有与列表中的另一个移动具有相同符号的移动?你知道吗
像这样的?一个小的双列表理解动作
我找到了一种更简洁的方法,但它牺牲了一些易读性:
相关问题 更多 >
编程相关推荐