[python]Update a list to a dictionary

the code below enumerate the list of vpc-id and make them into dictionary, the purpose is to make use of this dictionary to give a menu option for user.

import boto3


vpc_id_collector = []
menu_dict = {}
i=0
filter = [{'Name':'tag:Name', 'Values':['*']}]
ec2_client = boto3.client('ec2')
""":type : pyboto3.ec2"""
vpcs = ec2_client.describe_vpcs(Filters=filter)['Vpcs']
for vpc in vpcs:
    vpc_id_collector.append(vpc['VpcId'])
for i in range(len(vpc_id_collector)):
    j = i + 1
    menu_dict[j] = vpc_id_collector[i]
print(menu_dict)
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s