Python dict由值找键的方法

117 阅读1分钟

应用场景例如keyboard上任意一个字母,寻找所在行

参考CSDN,给出一种最容易想到的方法,分别创建两个list

student = {'小萌': '1001', '小智': '1002', '小强': '1003', '小明': '1004'}
list(student.keys())[list(student.values()).index('1002')]
# output:
# "小智"