【Python】sorted()函数作用

sorted()函数作用:

sorted(需要排序的数组, 依据数组的某一列为排序依据, 是否逆序)

sorted(classCount.iteritems(),key=operator.itemgetter(1),reverse=True)

  • 需要排序的数组:classCount.iteritems(),即为元组列表
  • 依据数组的某一列为排序依据:key=operator.itemgetter(1),即为根据第二列排序
  • 是否逆序:reverse=True,即需要逆序,从最大到最小排序
    【注】True的T是大写

猜你喜欢

转载自blog.csdn.net/weixin_38705903/article/details/79231588