If the values may appear in your list again, you can try this solution.
def search(Fscore_list, num=3): l = Fscore_list res = dict([(v, []) for v in sorted(set(l), reverse=True)[:num]]) for index, val in enumerate(l): if val in res: res[val].append(index) return sorted(res.items(), key=lambda x: x[0], reverse=True)
First, it will find num=3 the highest values and create a dict with an empty list for indexes for it. Then it will go through the list and for each of the highest values ( val in res ) will save its indices. Then just return the sorted list of tuples, for example [(highest_1, [indexes ...]), ..] . eg.
>>> l = [9, 7, 43, 2, 4, 7, 43, 8, 5, 8, 4] >>> print(search(l)) [(43, [2, 6]), (9, [0]), (8, [7, 9])]
To print line items, do something like:
>>> Fscore_list = [9, 7, 43, 2, 4, 7, 43, 8, 5, 8, 4, 43, 43, 43] >>> result = search(Fscore_list) >>> print("1st. %d on positions %s" % (result[0][0], result[0][1])) 1st. 43 on positions [2, 6, 11, 12, 13] >>> print("2nd. %d on positions %s" % (result[1][0], result[1][1])) 2nd. 9 on positions [0] >>> print("3rd. %d on positions %s" % (result[2][0], result[2][1])) 3rd. 8 on positions [7, 9]