【发布时间】:2022-01-25 18:13:04
【问题描述】:
我有以下字典,名为the_dictionary_list:
the_dictionary_list= {'Color': ['Amarillo.png', 'Blanco.png',
'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'],
'Cuerpo': ['Cuerpo_cangrejo.png'], 'Fondo': ['Oceano.png'], 'Ojos':
['Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas':
['Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas':
['Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}
我想检查它是否有一个具有特定值的特定键(在它的数组中),所以我输入了以下代码:
if ('Color', 'None') in the_dictionary_list.items():
print('This is True')
else:
print('This is False')
if ('Color', 'Amarillo.png') in the_dictionary_list.items():
print('This is True')
else:
print('This is False')
输出如下:
这是假的
这是假的
这是 50% 的错误,因为第二个 if statement 应该打印 This is True,我试图在其他站点中寻找答案,但似乎包含数组的字典非常罕见,但最终是合法的,否则如何我可以评估上面的字典中是否确实存在一对特定的键值?
【问题讨论】:
-
为什么不试试类似:
'Amarillo.png' in the_dictionary_list['Color']?
标签: arrays python-3.x dictionary if-statement notin