【Python】sorted()函数作用

sorted()函数作用:

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

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

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

转载于:https://www.cnblogs.com/Vincent-Lai/p/8438531.html

你可能感兴趣的:(python)