相关疑难解决方法(0)

使用列表中的max()/ min()获取返回的max或min项的索引

我在列表中使用Python maxmin函数来实现minimax算法,我需要max()或者返回的值的索引min().换句话说,我需要知道哪个移动产生了最大值(在第一个玩家的回合)或最小值(第二个玩家)值.

for i in range(9):
    newBoard = currentBoard.newBoardWithMove([i / 3, i % 3], player)

    if newBoard:
        temp = minMax(newBoard, depth + 1, not isMinLevel)  
        values.append(temp)

if isMinLevel:
    return min(values)
else:
    return max(values)
Run Code Online (Sandbox Code Playgroud)

我需要能够返回最小值或最大值的实际索引,而不仅仅是值.

python list max min

395
推荐指数
17
解决办法
74万
查看次数

基本Python列表

我需要有关如何找到哪个测试编号最小的帮助.这段代码将有助于解释.

test_list=[]
numbers_list=[]

while True:
    test=raw_input("Enter test or (exit to end): ")
    if test=="exit":
        break
    else:
        test_numbers=input("Enter number: ")
        test_list.append(test)
        numbers_list.append(test_numbers)
Run Code Online (Sandbox Code Playgroud)

如果test_list=['Test1','Test2','Test3']numbers_list=[2,1,3]

如何打印Test2的编号最小?由于Test2 = 1

python

0
推荐指数
1
解决办法
144
查看次数

标签 统计

python ×2

list ×1

max ×1

min ×1