# 示例代码01

 cnts = [2, 4, 3, 6, 5] boundingBoxes = [(730, 20, 54, 85), (651, 20, 53, 85), (571, 20, 53, 85), (492, 20, 53, 85), (412, 20, 53, 85)] ​ # b是zip中的一个元素,不确定是哪个,随机 (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),                                     key=lambda b: b[1][0], reverse=False)) print(cnts) print(boundingBoxes)
• 根据boundingBoxes中的每个元素的第一个值对cnts进行排序

• b是指打包后的一个元素,不确定是哪个,随机，比如[2, (730, 20, 54, 85)]

• reverse = False(默认), 从小到大排序, 否则从大到小

• key: 根据什么进行排序

## 运行结果01

 (5, 6, 3, 4, 2) ((412, 20, 53, 85), (492, 20, 53, 85), (571, 20, 53, 85), (651, 20, 53, 85), (730, 20, 54, 85))

## 示例代码02

 cnts = [2, 4, 3, 6, 5] boundingBoxes = [(730, 20, 54, 85), (651, 20, 53, 85), (571, 20, 53, 85), (492, 20, 53, 85), (412, 20, 53, 85)] ​ # b是zip中的一个元素,不确定是哪个,随机 (cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes),                                     key=lambda b: b[0], reverse=False)) print(cnts) print(boundingBoxes)
• 根据cnts,对boundingBoxes进行排序

## 运行结果02

 (2, 3, 4, 5, 6) ((730, 20, 54, 85), (571, 20, 53, 85), (651, 20, 53, 85), (412, 20, 53, 85), (492, 20, 53, 85))

posted on 2021-02-04 16:46  华子哈  阅读(547)  评论(0编辑  收藏  举报