2. 使用heapq庫,可以直接獲取最大值的下標(biāo)和數(shù)值。 1 2 3 4 5 6 7 8 importheapq a=[4,2,6,1,9,9] # 獲取下標(biāo), 輸出為[4, 5, 2] heapq.nlargest(3,range(len(a)), a.__getitem__) # 獲取數(shù)值, 輸出為[9, 9, 6] heapq.nlargest(3,a) ...
www.dbjr.com.cn/article/2127...htm 2025-5-25