【python基础】python字典根据值查询键

发布时间 2023-03-31 15:34:03作者: 鹅要长大

前言

 

测试

>>> tfl_label = {'circle_green':0, 'circle_red':1, 'circle_yellow':2, 'left_green':3, 'left_red':4, 'left_yellow':5, 'nomotor_green':6, 'nomotor_red':7, 'nomotor_yellow':8, 'off':9}
>>> classid=2
>>> label = list(tfl_label.keys())[list(tfl_label.values()).index(classid)]
>>> label
'circle_yellow'

 

 

参考

1. python字典根据值找键_M3ng@L的博客-CSDN博客