def sort_list_by_indexList(list_to_sort,index_list):
'''
:param list_to_sort: a n_length list like [5,99,6,4,2]
:param index_list: a n_length list like [2,1,0,3,4]
:return: return a list = [6,99,5,4,2]
'''
list_length= len(list_to_sort)
list_to_sort_copy =copy.deepcopy(list_to_sort)
list_to_sort_old = copy.deepcopy(list_to_sort)
for i in range(list_length):
list_to_sort_copy[i] = list_to_sort_old[ index_list[i] ]
return list_to_sort_copy
sorted_id = copy.deepcopy(sorted(range(len(self.each_best_fitness)),
key=lambda k: self.each_best_fitness[k], reverse=False))
self.each_particles = sort_list_by_indexList(list_to_sort=self.each_particles, index_list=sorted_id)
a = [1, 3, 4, 5, 2, 7, 9]
print('a:', a)
sorted_id = sorted(range(len(a)), key=lambda k: a[k], reverse=True)
print('元素索引序列:', sorted_id)
a: [1, 3, 4, 5, 2, 7, 9]
元素索引序列: [6, 5, 3, 2, 1, 4, 0]