qcmuu / notebook

MIT License
0 stars 0 forks source link

Return the index of the max numbers #4

Open qcmuu opened 5 years ago

qcmuu commented 5 years ago

-- coding: utf-8 --

import heapq

nums = [1, 8, 2, 23, 7, -4, 18, 23, 24, 37, 2]

最大的3个数的索引

max_num_index_list = map(nums.index, heapq.nlargest(3, nums))

最小的3个数的索引

min_num_index_list = map(nums.index, heapq.nsmallest(3, nums))

print(list(max_num_index_list)) print(list(min_num_index_list))

From https://blog.csdn.net/ns2250225/article/details/80118621