按value排序
sorted(coupon_scores.items(), key=lambda x: x[1], reverse=True)
按key排序
sorted(coupon_scores.items(), key=lambda x: x[0], reverse=True)
sorted(coupon_scores.items(), key=lambda x: x[1], reverse=True)
sorted(coupon_scores.items(), key=lambda x: x[0], reverse=True)
本文标题:【Python小技巧】字典按key/value排序
本文链接:https://www.haomeiwen.com/subject/mhcewftx.html
网友评论