基于知道其他键值boto3来获取数组内部对象中的键/值

问题描述

"clone": [
        {
            "href": "http://abc.compute.amazonaws.com:7990/scm/fin/test.git","name": "http",},{
            "href": "ssh://[email protected]mpute.amazonaws.com:7999/fin/test.git","name": "ssh",]

我有一个带有两个随机移动的对象的数组,如何使用python引用名称(保持静态),从而在第一个对象内提取 href 值boto3。

解决方法

您可以进行线性搜索:

href = next(x for x in array if x['name']=='ssh')['href']

如果您的array没有匹配name的字典/对象,则会抛出异常。