gpt4 book ai didi

python - 获取键对应于字典中的值

转载 作者:太空狗 更新时间:2023-10-29 22:03:48 25 4
gpt4 key购买 nike

我在 python 中有这本字典

d={1: 'a', 2: 'b', 3: 'c'}

用 d[1] 我得到

>>> d[1]
'a'

如何让键对应一个值?
示例:使用 'a' 得到 1

最佳答案

你想反转映射:

如图this question

dict((v,k) for k, v in map.iteritems())

关于python - 获取键对应于字典中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8650415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com