Python - 字典列表中的值

标签 python

<分区>

Possible Duplicate:
What's the best way to search for a Python dictionary value in a list of dictionaries?

我有一个表单中的字典列表

my_dict_list = []
my_dict_list.append({'text':'first value', 'value':'number 1'})
my_dict_list.append({'text':'second value', 'value':'number 2'})
my_dict_list.append({'text':'third value', 'value':'number 3'})

我还有另一个表格形式的列表:

results = ['number 1', 'number 4']

我如何遍历 results 列表,检查值是否在 dict 中,例如

for r in results:
    if r in my_dict_list:
        print "ok"

最佳答案

for r in result:
  for d in dict:
    if d['value'] == r:
       print "ok"

关于Python - 字典列表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5665114/

相关文章:

python - 根据 Google Cloud Bigtable 中的唯一 ID 选择 JSON 对象

python - 为什么我不能迭代(多处理)管理器列表?

python - 我如何与 Python 内核交互 JupyterLab 扩展?

python - Python 中反向集合运算符的实际使用

python - 如何在 pandas 数据框中使用 groupby 查找描述性统计数据

python - 在 Django 中渲染模板变量时出现问题

python - 如何将图像文件保存在 Postgres 数据库中?

python - 处理 SheetsAPI 错误 - Python 2.7

Python Visual Studio Code autoDocstring 配置

python - 电子邮件消息 python 抓取消息的一部分