Python列表到映射列表

2024-10-01 02:25:36 发布

您现在位置:Python中文网/ 问答频道 /正文

ENV:python3.7+,boto3

我有私有IP地址列表['10.0.3.11','10.0.2.22']

response = route53_client.change_resource_record_sets(
           HostedZoneId="ABDCEFGH",
           ChangeBatch={
               'Comment': 'Dns to ec2 instance',
               'Changes': [
                   {
                       'Action': 'UPSERT',
                       'ResourceRecordSet': {
                           'Name': "ts-uat",
                           'Type': 'A',
                           'TTL': 120,
                           'ResourceRecords': [
                              {
                                   'Value': record['Value']
                              },
                          ]
                       }
                   }
               ]
           }
       )

如何得到它如下

            HostedZoneId="ABDCEFGH",
            ChangeBatch={
                'Comment': 'Dns to ec2 instance',
                'Changes': [
                    {
                        'Action': 'UPSERT',
                        'ResourceRecordSet': {
                            'Name': "ts-uat",
                            'Type': 'A',
                            'TTL': 120,
                            'ResourceRecords': [
                               {
                                   'Value': 10.0.3.11
                               },
                               {
                                   'Value': 10.0.2.22
                               },
                            ]
                        }
                    }
                ]
            }
        )

我尝试了以下方法

def getListofIP(n):
    return "{'value' : %s,}" %  (n) 
result = map(getListofIP, private_ip)
print(list(result))

产量为

[“{'value':10.0.3.11,}”,“{'value':10.0.2.22,}”]


Tags: toinstancevaluednscommentactionrecordec2