hi, I have the following problem. I have a list of...
# general
c
hi, I have the following problem. I have a list of subnet cidrs that is
Output[list[str]]
['10.10.16.0/24', '10.10.17.0/24', '10.10.18.0/25', '10.10.18.128/25', '10.10.19.0/27', '10.10.19.32/27']
it must be output, because it can be known only after some other resources have been provisioned. now, I need to create a subnet based on the index, simplified sample looks like this:
Copy code
for j, subnet in enumerate(subnets):
        print(j, subnet.name)
        subnet_cidrs.apply(lambda cidrs: print(subnet.name, cidrs[j]))
but the output is not what I expect:
Copy code
0 int-az1
    1 int-az2
    2 ext-az1
    3 ext-az2
    4 db-az1
    5 db-az2
========
    db-az2 10.10.19.32/27
    db-az2 10.10.19.32/27
    db-az2 10.10.19.32/27
    db-az2 10.10.19.32/27
    db-az2 10.10.19.32/27
    db-az2 10.10.19.32/27
it is very weird behavior. I suspect that
apply
doesnt play well inside the for loop, where the value
j
is changing, but I am not sure how to solve it. any suggestions?
a
does this do anything different?
Copy code
for j, subnet in enumerate(subnets):
        print(j, subnet.name)
        inner_j = j
        subnet_cidrs.apply(lambda cidrs: print(subnet.name, cidrs[inner_j]))
or
Copy code
for j, subnet in enumerate(subnets):
    print(j, subnet.name)
    subnet_cidrs.apply(lambda cidrs, j=j: print(subnet.name, cidrs[j]))
c
@able-ability-55163 first doesn't work, but second works. thanks! also works using partial