【问题标题】:How to evaluate if a particular value exists in every single key in a dictionary that has arrays as values on Python?python - 如何评估一个特定值是否存在于字典中的每个键中,该字典具有数组作为Python上的值?
【发布时间】:2022-01-02 05:00:20
【问题描述】:

假设我在 Python 程序中有以下字典:

the_dictionary_list = {'Color': ['None', 'Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Cuerpo': ['None', 'Cuerpo_cangrejo.png'], 'Fondo': ['None', 'Oceano.png'], 'Ojos': ['None', 'Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas': ['None', 'Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['None', 'Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}

如何验证上面字典中的每个键中都存在元素 'None'

【问题讨论】:

    标签: arrays python-3.x loops dictionary


    【解决方案1】:

    all(['None' in v for k, v in the_dictionary_list.items()])

    这将遍历字典键值对并返回 TrueFalse 如果 'None' 在值中。然后all 检查它们是否都为真,如果一个为假,则返回False,如果均为True,则返回真

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 2021-08-19
      • 2011-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 2014-03-29
      • 1970-01-01
      相关资源
      最近更新 更多