python-2.7 - 如何在 boto3 python2.7 list dict 对象中搜索值 - list_tags_for_resource
问题描述
我在下面有响应对象
response = source.list_tags_for_resource(ResourceName=<ARN>)
taglistk = response['TagList']
print(taglistk)
输出 :
[{'Value': 'yes', 'Key': 'az'},{'Value': 'dba', 'Key': 'created'},{'Value': 'mariadb', 'Key': 'service'}]
现在我想写一个 for if 条件来匹配 K,V az=yes 和 service=mariadb 并做一些事情
解决方案
从响应的标签列表中,通过for循环选择一个标签并检查给定键的值,即Key和Value。
response = source.list_tags_for_resource(ResourceName=<ARN>)
for item in response:
if item['Key'] == 'az' and item['Value'] == 'yes':
# do something with item
elif item['Key'] == 'service' and item['Value'] == 'mariadb':
# do otherthing with item
else:
continue
推荐阅读
- mysql - 从表 T 中选择:计算中位数时此模式如何工作
- sql - Oracle:遍历表并为每个行名打印一个 xml 文件
- django - 匿名用户的外键
- ios - iOS 13 未获得 VoIP 推送令牌
- c - 在 C 中返回“数据类型”
- java - Spring Boot Controller 测试 - 当 thenReturn 列表不起作用时 Mockito
- jquery - 验证电子邮件字段并确保不为空
- c# - 从 SqlDatareader 返回多行
- powershell - '<' 运算符保留供将来使用命令 powershell
- python - 如何使用“名称”而不是 id 从 SQLite 中删除记录?