Python避免嵌套for循环

时间:2020-06-24 15:25:21

标签: python-3.x

我在使用嵌套循环的这段代码中

res1 = EC2_CLIENT.describe_instances(
            InstanceIds=[ec2_id,
            ],
        )['Reservations']
        
        print (res1)
        
        for r in res1:
            inst = r['Instances']
            for i in inst:
                ni = i['NetworkInterfaces']
                for n in ni:
                    g = n['Groups']
                    for g1 in g:
                        groupId = g1['GroupId']`

有没有一种方法可以简化这段代码来检索groupId?

0 个答案:

没有答案