小编Jon*_*as 的帖子

如果给定字符串与字典中的键值匹配,如何返回键

我是字典的新手,我试图找出如果给定的字符串匹配字典中的键值,如何返回键.

例:

dict = {"color": (red, blue, green), "someothercolor": (orange, blue, white)}
Run Code Online (Sandbox Code Playgroud)

我想回到colorsomeothercolor,如果键的值包含blue.

有什么建议?

python dictionary

4
推荐指数
1
解决办法
5873
查看次数

如果elif一个班轮

if i == len(a):
   tempList.extend(b[j:])
   break
elif j == len(b):
   tempList.extend(a[i:])
   break
Run Code Online (Sandbox Code Playgroud)

我在Python的mergesort程序中使用它.有没有办法把它变成一个oneliner?

python-3.x

-3
推荐指数
1
解决办法
68
查看次数

标签 统计

dictionary ×1

python ×1

python-3.x ×1