What's the best way to achieve this `for` loop her...
# python
c
What's the best way to achieve this
for
loop here?
Copy code
vnet = network.VirtualNetwork('ssvc-vnet',
  resource_group_name=resource_group.name,
  name="ssvc-vnet-{0}".format(stack_name),
  address_spaces=[ssvc_vnet_space],
  subnets= [
    for subnet in subnet_config:
      {
        name=subnet[0],
        address_prefix=subnet[1],
        virtual_network_name=vnet.name
      )
      },
  ]
)
It's syntactically incorrect, so I'm wondering what the best way to get this done anyways might be.
okay, this works:
Copy code
custom_subnets = []
for subnet in subnet_config:
  custom_subnets.append({"name":subnet[0],"address_prefix":subnet[1]})

# networking resources
vnet = network.VirtualNetwork('ssvc-vnet',
  resource_group_name=resource_group.name,
  name="ssvc-vnet-{0}".format(stack_name),
  address_spaces=[ssvc_vnet_space],
  subnets=custom_subnets
)
n
alternatively, using list comprehension:
Copy code
subnets = [
    {
        name=subnet[0],
        address_prefix=subnet[1],
        virtual_network_name=vnet.name
    } for subnet in subnet_config
]
👍🏽 2
c
oh, that's so much nicer!
n
Copy code
subnets = [
    {
        "name":subnet[0],
        "address_prefix": subnet[1],
        "virtual_network_name": vnet.name
    } for subnet in subnet_config
]
fixed the dict, = wont' work