我试图通过其中一个属性在python中对列表进行排序,但是,它没有正确排序,任何提示。
我尝试在排序前后打印值,它们打印相同的值。
def kmeans_clustering(cluster_list, num_clusters, num_iterations):
"""
Compute the k-means clustering of a set of clusters
Input: List of clusters, number of clusters, number of iterations
Output: List of clusters whose length is num_clusters
"""
# initialize k-means clusters to be initial clusters with largest populations
for idx in range(len(cluster_list)):
print cluster_list[idx].total_population()
print "sort.."
sorted(cluster_list, key = lambda x: x.total_population(), reverse = True)
for idx in range(len(cluster_list)):
print cluster_list[idx].total_population()