我从 AWS 得到一个 python 字典,其格式类似于以下示例对象:
{'ResponseMetadata': {'NOT IMPORTANT'},
'hasMoreResults': True,
'marker': '{"NOT IMPORTANT"}',
'pipelineIdList': [{'id': 'df-0001',
'name': 'Blue'},
{'id': 'df-0002',
'name': 'Orange'},
{'id': 'df-0003',
'name': 'Green'},
{'id': 'df-0004',
'name': 'Red'},
{'id': 'df-0005',
'name': 'Purple'}
]}
我想要求name输入pipelineIdList并获得id与之匹配的输入。例如,如果您使用输入字符串“Red”进行搜索,您将获得“df-0004”的返回值
我的代码如下:
import boto3
def findId(pipeline_list, inputString):
for dict in pipeline_list:
if dict['pipelineIdList']['name'] == inputString:
return dict['id']
def main():
inputString = "Red"
datapipeline = boto3.client('datapipeline')
pipeline_list = datapipeline.list_pipelines() //This line returns a Dict like the one above
result = findId(pipeline_list, inputString)
print(result)
if __name__ == "__main__":
main()
在print(result)这种情况下, withinputString="Red"应该打印一个 值df-0004,但它完全不打印任何内容。任何有关解决此问题的帮助将不胜感激。
ABOUTYOU
慕森王
相关分类