python - 将列表中的值与列表中的字典值进行比较
问题描述
我在列表中有一本字典:
list1 = [{'Value': 'John','Key': 'Name'},{'Value':'17','Key': 'Number'}]
我有一个清单:
list2 = ['Name','Number']
如何检查list2中的值存在于list1中。如果存在,我需要列出Value。
例如:如果存在 Name ,则打印“ John ”
解决方案
另请阅读评论:
for i in list2: #iterate through list2
for j in list1: #iterate through list of dictinaries
if i in j.values(): #if value of list2 present in the values of a dict then proceed
print(j['Value'])
推荐阅读
- linux - gl.h:没有这样的文件或目录,我似乎无法平息这个错误
- kotlin - Kotlin,DialogFrag 宽高百分比
- apache-spark - Spark shuffle 写入量很大
- elasticsearch - 手动删除弹性搜索上的索引不释放空间
- python - 如何在现有表中添加新列 uaing jdbc pyspark python?
- python - 使用 Github 操作在子模块中测试 python 代码
- python - 需要在熊猫中将某个日期一年内的日期数相加
- python - “WebDriver”对象没有属性“Chrome”
- stack - 从 LLVM IR 获取函数的堆栈帧大小
- rust - 为什么移动值会生成包含值副本的 LLVM IR?